Trying to get property of non-object - Middleware - laravel 5.4

0

Dear, I have a project in Laravel 5.4 and I have 3 types of users (Administrator, staff and client) With the Administrator I have no problems, but when I assign some methods of some controllers to the personnel middleware and try to access them, I get the error of the photo.

I have tried with methods and routes with and without parameters and with all the attempts it throws me the same error. I leave the code of some files related to the middleware.

Route / web

Route::group(['prefix' => 'admin', 'middleware' => ['administrador','personal']], function(){
Route::resource('ot', 'OTController');
Route::resource('rol', 'RolController');
Route::resource('sucursal', 'SucursalController');
Route::resource('servicio', 'ServicioController');
Route::get('/servicio/crear/{id_ot}', 'ServicioController@crear')->name('servicio.create');
Route::get('/servicio/recuperar/{id}', 'ServicioController@recuperar')->name('servicio.recuperar');
Route::resource('mensaje', 'MensajeController');
Route::get('home', function(){
    return view('admin.home');
});

});

Controller / Middleware / personal.php

public function handle($request, Closure $next)
{
    if(Auth::user()->rol_id == 2) {
        return $next($request);
    }else{
        return route('login');
    }
}

In addition, I have added the middleware of both administrator and staff and the client in the kernel.php

'personal'      => \App\Http\Middleware\personal::class,

I have reviewed the routes ("php artisan route: list") and effectively the controllers' methods appear with administrator and personnel permission. I must clarify that only as a test I have granted the same permissions for administrator as for personnel since in production period only some methods of some controllers will give access to personnel (that I have already solved).

I have searched for information, tried variants and created middleware several times without good results.

If you need more information, please let me know and I will add it.

I remain attentive, Thanks!

Controller / Middleware / admin.php

public function handle($request, Closure $next) {
    if(Auth::user()->rol_id == 1) {
        return $next($request);
    }else{
        return route('login');
    }
}
    
asked by Israel jara 22.06.2017 в 22:38
source

0 answers