2016-04-25 92 views
0

在我的项目中我需要保护一些视图。我在现场控制user auth Laravel 5.2

Route::group(['middleware' => ['auth']], function(){ 

//Spot 
    Route::get('administrator/spot-new', '[email protected]'); 
    Route::post('administrator/spot-new', '[email protected]'); 
} 

: 我创建了一个路由器组

public function __construct() 
{ 
    $this->middleware('auth'); 
} 

但是当我尝试进入现场查看,我不能看到登录页面。 我有这个错误: 对不起,找不到您正在寻找的页面。

+0

检查了这一点,也许它可以帮助你http://stackoverflow.com/questions/36567068/laravel-5-2-auth-registration-page-blocked/36567538#36567538 –

+0

使用[“中间件” => ['web','auth']] –

+0

in Authenticate middleware if(Auth :: guard($ guard) - > guest()){$ request-> ajax()|| $ request-> wantsJson()){ return response('Unauthorized。',401); } else { return redirect() - > guest('auth/login'); } } –

回答

0

Laravel 5.2添加了中间件组。对于开始会话/加密饼干/验证CSRF令牌等等。见下面

protected $middlewareGroups = [ 
    'web' => [ 
     \App\Http\Middleware\EncryptCookies::class, 
     \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
     \Illuminate\Session\Middleware\StartSession::class, 
     \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
     \App\Http\Middleware\VerifyCsrfToken::class, 
    ], 

You're required to add when working with sessions and any other stuff in that group.

所以要解决你的问题添加 '网络' 到

https://laravel.com/docs/5.2/middleware#middleware-groups

的Web中间件组负责你的中间件

Route::group(['middleware' => ['web', 'auth']], function(){ 
    Route::get('administrator/spot-new', '[email protected]'); 
    Route::post('administrator/spot-new', '[email protected]'); 
} 

而在你的控制器构造函数

public function __construct() 
{ 
    //$this->middleware('auth'); (No need for this one) 
}