Filters in Laravel 5

后端 未结 8 987
南笙
南笙 2021-01-31 08:12

How do we make filters in Laravel 5? Is the idea of filters going away?

8条回答
  •  一生所求
    2021-01-31 08:27

    I personally think that adding a middleware is a good practice, but if you happen to ever need a quick small filtering for a controller, rubyonrails-style,

    do as follows:

    class myController{
    
       //filters
       public function myFilter()
       {
          //my filter's logic
       }
    
       public function __construct()
       {
         $this->myFilter();
         //middlewares or any other code
       }
    
    
     }
    

提交回复
热议问题