undefined variable error laravel 5.5

Posted 5 months ago by daniel21gt

I have an undefined variable error, which in fact if it is defined, it is called $filtros, the code is this.

public function excelestados(Request $request)
{        
   
   $registrado = \Auth::user()->tipos_usuarios_id;
   $filtros = \Auth::user()->username;

   if($registrado == 1)

    {
        $request->user()->authorizeRoles(['admin']);

        Excel::create('ExcelEstados', function($excelestados) {
        $excelestados->sheet('Excelsheet', function($sheet) {
         

          $conteoestados = usuarios::whereNotNull('asignacion')->get();

              $conteoestados = json_decode( json_encode($conteoestados), true);

              $sheet->fromArray($conteoestados);
              $sheet->setOrientation('landscape');
          
        });

    })->export('xls');
   
   }


  if($registrado == 3)
   
    {

        $request->user()->authorizeRoles(['gestion']);
        
        Excel::create('ExcelEstados', function($excelestados) {
        $excelestados->sheet('Excelsheet', function($sheet) {
         

          $conteoestados = usuarios::whereNotNull('asignacion')->where('asignacion', $filtros)->get();

              $conteoestados = json_decode( json_encode($conteoestados), true);

              $sheet->fromArray($conteoestados);
              $sheet->setOrientation('landscape');
          
        });

    })->export('xls');

  }

}

If I enter as admin, I enter well, but as a manager I get this error, I already checked that the variable $filtros really had value, but even so I get that error.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.