Laravel 5.6 Undefined variable: insurer

0

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.

    
asked by Carlos Roberto Luna Ochoa 28.08.2018 в 19:54
source

1 answer

0

you must use the use, if the variable does not arrive

public function mostrarVehNAs(Request $request){
$aseguradora = $request -> input ('sel_as');
$datos = \DB::table ('crlo_vehiculos') 
        ->whereNotIn('id_vehiculo', function($query) use ($aseguradora) {
            $as = $aseguradora; //Aqui marca el error
                $query->select('id_vehiculo')
                ->from('crlo_veh_asegurados')
                ->where('id_aseguradora', '=', $as);
        })->get();
return $datos;
    
answered by 12.09.2018 в 15:35