Form Request Validation: Creating Form Requests
Creating Form Requests
Creating Form Requests — Are custom request classes that contain validation logic.
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
];
} /**
* Store the incoming blog post.
*
* @param StoreBlogPost $request
* @return Response
*/
public function store(StoreBlogPost $request)
{
// The incoming request is valid...
// Retrieve the validated input data...
$validated = $request->validated();
} The incoming form request is validated before the controller method is called, meaning you do not need to clutter your controller with any validation logic.
- App/Http/Requests.
Related concepts
→
Creating Form Requests
Semantic portal