Protecting all admin/ routes with auth in Laravel

前端 未结 3 1189

I am brand new to laravel and am setting up admin panel authorization on my first application. The way I have my files setup currently setup is:

controllers/
             


        
3条回答
  •  萌比男神i
    2021-02-06 01:49

    For future readers, a very clean way to handle this is using Laravel's Route Groups:

    Route groups allow you to share route attributes, such as middleware or namespaces, across a large number of routes without needing to define those attributes on each individual route.

    Route::group(['middleware' => 'auth'], function () {
        Route::get('/', function ()    {
            // Uses Auth Middleware
        });
    
        Route::get('user/profile', function () {
            // Uses Auth Middleware
        });
    });
    

    They can be used not only for authentication, but also Namespaces, Sub-Domains, and more.

提交回复
热议问题