Laravel 5 - Call to middleware from controller method

September 28, 2018 | Category : Laravel PHP

In this post, i will let you know to call middleware from controller method using $this-middleware.

Here i will show you constructor for adding middleware for each method like index, create, store, edit, delete, show and update of controller.

You can see bellow code how we can use middleware in your controller file. It might be help to use middleware with "only" or "except" method too.



* Create a new controller instance.


* @return void


public function __construct()


$this->middleware('product-list', ['only' => ['index']]);

$this->middleware('product-create', ['only' => ['index','create','store']]);

$this->middleware('product-update', ['only' => ['index','edit','update']]);

$this->middleware('product-delete', ['only' => ['index','delete']]);


I hope you found your best solution...