In this tutorial we're going to investigate how we can reuse the logic in Laravel Form requests for the difference between Create and Update requests. Laravel form requests are great, they allow you to include all the validation and authentication logic in the request object and you will know everything in the controller has already been validated.

* * @return array */ public function rules() { return [ 'title' => 'required|string', 'content' => 'required|string' ]; }} https://paulund.co.uk/dry-create-and-update-laravel-form-requests#update-post class UpdatePost extends FormRequest { /** * Get the validation rules that apply to the request.

As the UpdatePost request is the same as the CreatePost but with an extra field, why not just reuse the CreatePost request rules.

class UpdatePost extends CreatePost { /** * Get the validation rules that apply to the request.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners