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

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -