A
A
Apostol632020-02-13 12:32:14
Laravel
Apostol63, 2020-02-13 12:32:14

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');


But in the code section return route('login');
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);
    }
}

error is thrown Trying to get property of non-object

Laravel answer:
5e45175f885f9007308589.png
What am I missing? Still as in the documentation
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Musonov, 2020-02-13
@Apostol63

Route named login specified?
Better to do
return redirect()->route('name')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question