The question is that I need to enter a% conditional where
, according to the data that is sent to the controller, the question one of those conditions is that I bring the data according to a select
, I already tried the query in the manager of data, but in laravel
I guess it is represented in another way, this is what I tried.
$data = DB::table('historico_establecimientos')
->where(function($data) use ($location,$anio,$mes) {
if($location=="due") {
$data->where("anio_corte",$anio);
$data->where("mes_corte",$mes);
}else{
$data->where("anio_corte",('select MAX(anio_corte) from historico_establecimientos'));'introducir el código aquí'
$data->where("mes_corte",('select MAX(mes_corte) from historico_establecimientos'));
}
})
->orderBy("nombre_establecimiento","ASC")
->get();
Query sql
select * from historico_establecimientos where anio_corte = (select
MAX(anio_corte) from historico_establecimientos) and mes_corte = (select
MAX(mes_corte) from historico_establecimientos)