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...
Do you like below Tutorials ?
- Laravel 5.7 Image Upload with Validation Example
- Laravel 5.7 get ip address
- Email Verification in laravel 5.7 Example
- Calculate age from date of birth in Laravel
- Get date on change event of Bootstrap Datepicker
- PHP Laravel 7.x and 6.x Union query Example