Answer the question
In order to leave comments, you need to log in
Why does the return route() in the middleware give an error Trying to get property of non-object?
Good day everyone!
I made my own middleware (via php artisan. Everything is as in the documentation).
I apply it to the route
Route::get('/midd', '[email protected]')->middleware('mymidd');
class Checkauth
{
public function handle($request, Closure $next) {
if(Auth::check()) {
file_put_contents(__DIR__ . '/check1.txt', 'check1');
} else {
file_put_contents(__DIR__ . '/check2.txt', 'check2');
return route('login');
}
return $next($request);
}
}
Answer the question
In order to leave comments, you need to log in
Route named login specified?
Better to do
return redirect()->route('name')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question