How to group laravel routes based on logged users and guest users

Chathurika Mahanama picture Chathurika Mahanama · May 30, 2016 · Viewed 7.9k times · Source

I want to group the Laravel 5 routs based on the logged users and guest users. Is there any inbuilt framework methods in Laravel 5 to do this?

Answer

Giedrius Kiršys picture Giedrius Kiršys · May 30, 2016

Yes, there are some: https://laravel.com/docs/master/middleware#assigning-middleware-to-routes auth for authorized and guest for guests.

Route::group(['middleware' => ['auth']], function () {
    //only authorized users can access these routes
});

Route::group(['middleware' => ['guest']], function () {
    //only guests can access these routes
});