Answer the question
In order to leave comments, you need to log in
How can I fix the error trying to get property of non-object in laravel?
I get this error if an unauthenticated user tries to navigate the route
Route::get('home', '[email protected]')->name('home');
public function handle(Request $request, Closure $next)
{
if(\Auth::user()->role_id != 1) {
return redirect('')->with('success', 'Я вас сюда не звал');
}
return $next($request);
}
Answer the question
In order to leave comments, you need to log in
At you there is a check of already authorized user. Therefore, you first need to check if the user is authorized. If not, send to the authorization page, and if yes, then check the role_id property.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question