Filters in Laravel 5

后端 未结 8 1008
南笙
南笙 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:43

    It seems like middlewares are replacing filters for Laravel. As for your question. The right answer is Middlewares. Think of it as layers.

    For a more detailed answer check this out.

    old answer

    A quick search showed requests to be the new way of validating. But I'm not sure if your use case can apply to this.

    Laravel 5 introduces the notion of “requests”. This is wrapping up logic that you would perform as part of a HTTP request, but are more than just a route filter. A prime candidate: data validation.

    One way of doing pre-validation (filter) is by using the method authorize().

     'required|email|unique:users',
                'password' => 'required|confirmed|min:8',
            ];
        }
    
        public function authorize()
        {
            return true;
        }
    
    }
    

    There’s a rules() method that returns an array of rules you would before pass to Validator::make(), and also an authorize() method where you would provide any user authorisation. Usually you want all users to be able to register, so you just simply return true.

    Taken from What's new in Laravel 5

提交回复
热议问题