php - How to ensure user is authenticated before he publishes an article in Laravel in the below scenario? -
i developing simple web blogging application in laravel 5.1. application contains 2 controllers, userscontroller
, articlescontroller
.
the authenticate()
, check()
functions validate whether user authorized carry out operation in userscontroller
, , store()
, update()
etc. features related articles in articlescontroller
.
how supposed call authenticate()
or check()
function articlescontroller
before say, store()
ing article database?
laravel uses middleware, in controller need put this
public function __construct(){ $this->middleware('auth'); //requires auth }
and in routes need add code use middleware in needed controllers this
route::group(['middleware' => 'auth'], function () { route::get('/', function () { // uses auth middleware }); route::get('user/profile', function () { // uses auth middleware }); });
read documentation of laravel middleware can create more middleware http://laravel.com/docs/master/middleware
Comments
Post a Comment