moving from thinkphp to laravel broadens a lot of ideas. I have to say that laravel is really a good product, especially in terms of php project code standards and specifications.
but thinkphp also has some good features, such as verification scenarios, sometimes there are some differences in different business verification fields, for example, the password field must be entered when the user registers, but the password is optional when the user profile is changed. Redefining a validator is wasteful and can be well solved with scenarios.
do verification in laravel. I usually do this
.1. Generate form request class
php artisan make:request StoreBlogPost
2.StoreBlogPost.php write validation rules
`public function rules ()
{
return [
"name"=>"required",
"email"=>"required|unique:users",
"password"=>"required|confirmed"
];
}
public function message(){
.....
}
`
3. Verify in the controller
public function store(StoreBlogPost $request)
{
$user=User::create([
"name"=>$request->input("name"),
"email"=>$request->input("email"),
"password"=>bcrypt($request->password)
]);
....
}
how to add a verification scenario to the validator. A mature extension package is also available.
Please give us some suggestions. Thank you