authentication - user auth Laravel 5.2 -
in project need protect views. create router group:
route::group(['middleware' => ['auth']], function (){ //spot route::get('administrator/spot-new', 'spotcontroller@create'); route::post('administrator/spot-new', 'spotcontroller@store'); }
in spot controller:
public function __construct() { $this->middleware('auth'); }
but when try access spot view can't see login page. have error: sorry, page looking not found.
laravel 5.2 have added middleware groups.
https://laravel.com/docs/5.2/middleware#middleware-groups
web middleware group responsible start session / encrypt cookies / verify csrf token etc.. see below
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 add when working sessions , other stuff in group.
so solve problem add 'web' middleware
route::group(['middleware' => ['web', 'auth']], function (){ route::get('administrator/spot-new', 'spotcontroller@create'); route::post('administrator/spot-new', 'spotcontroller@store'); }
and in controller constructor
public function __construct() { //$this->middleware('auth'); (no need one) }
Comments
Post a Comment