Using $this->validate
on the controller action automates the whole process significantly. If the validation fails, it automatically redirects to the previous page, while a list of errors should be available in $errors
variable in your view.
If you want to have a control over the process you can do it that way:
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
if ($validator->fails()) {
return $validator->errors();
}
// Validation successful
Please see https://laravel.com/docs/5.4/validation for more information.