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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners