I have a driver where I made a function so that, according to a selected insurer, I returned the vehicles that are not registered in that insurer. When the function is executed, it sends me the error:
"Undefined variable: insurer"
This is the function:
public function mostrarVehNAs(Request $request){
$aseguradora = $request -> input ('sel_as');
$datos = \DB::table ('crlo_vehiculos')
->whereNotIn('id_vehiculo', function($query) {
$as = $aseguradora; //Aqui marca el error
$query->select('id_vehiculo')
->from('crlo_veh_asegurados')
->where('id_aseguradora', '=', $as);
})->get();
return $datos;
}
And here is the complete controller .
Try to make the following query and this one if it returns results:
public function mostrarVehNAs(Request $request){
$datos = \DB::table ('crlo_vehiculos')
->whereNotIn('id_vehiculo', function($query) {
$query->select('id_vehiculo')
->from('crlo_veh_asegurados')
->where('id_aseguradora', 1);
})->get();
return $datos;
}
Thank you in advance for your answers.