簡體   English   中英

在laravel 5.2中使用auth中間件組限制路由

[英]Restricting routes with auth middleware group in laravel 5.2

我試圖阻止人們訪問/dashboard路由,除非他們經過身份驗證(登錄)。 我查看了laravel文檔,這是我認為應該完成的工作。

Route::group(['middleware' => 'auth'], function (){
    Route::get('/dashboard', [
        'uses' => 'UserController@getDashboard',
        'as' => 'dashboard'
    ]);
});

您無需在路由中添加該額外的中間件。 只需使用該組,您就可以了。 您可以在這里看到: https : //laravel.com/docs/5.1/routing#route-groups

Route::group(['middleware' => 'auth'], function () {
    // User needs to be authenticated to enter here.
    Route::get('/', function ()    {
        // Uses Auth Middleware
    });

    Route::get('user/profile', function () {
        // Uses Auth Middleware
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM