Laravel Magazine
Form Request Validation Tips for Cleaner Controllers
Featured

Form Request Validation Tips for Cleaner Controllers

If your controllers are still calling $request->validate([...]) inline, you are leaving a lot of Laravel's best validation features on the table. Form Requests move validation, authorization, and input preparation out of the controller and into a single dedicated class. Here is how to use them well. Return Only Validated Data The single most useful habit: never pull raw input into your create and update calls. Use validated() so only the fields that passed validation reach your model: public function store(StorePostRequest $request) { // Only validated keys — no mass-assignment surprises $post = Post::create($request->validated()); return redirect()->route('posts.show', $post); } Need a subset? safe() gives you only() and except(): $data = $request->safe()->only(['title', 'body']); $data = $request->safe()->except(['published_at']); Put Authorization Where It Belongs The authorize() method runs before validation. Use it to keep permission checks out of the controller entirely: public f...

Recent Articles

Latest Links

Stay Updated

Subscribe to our newsletter

Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.

Weekly articles
We send a new issue of the newsletter every week on Friday.
No spam
We'll never share your email address and you can opt out at any time.