E
E
Elsa122018-07-20 17:52:06
Laravel
Elsa12, 2018-07-20 17:52:06

How to redirect an authorized user at the route level?

Hey! I have a page on the site, index - /, and I want to have access to it only for non-registered users, how to implement the redirect "correctly"? Now it works like this for me, but as far as I know, these are crutches ... I would be glad if you explain what is wrong, thanks!

Route::get('/', function () {
    if(Auth::check()){
    	return redirect()->route('home');
    }else{
    	return view('index');
    }
});

PS I use the standard authorization module

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shahob I, 2018-07-20
@Elsa12

Use Middleware
More details here https://laravel.com/docs/5.6/authentication

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question