Your Controller Is Doing Too Much Work

Open your controller. Look at your store method.

Does it have 40 lines of code? Does it start with a massive validation block, followed by several if statements, then business logic, and finally a return?

Your controller is doing work that is not its job.

A controller has one simple role. It receives a request, calls a service to solve the problem, and returns a response. Think of it as a waiter. A waiter brings your food. They do not cook it.

When you put validation, authorization, and data processing inside a controller, it becomes a mess. You end up with an 80-line monster that no one wants to touch.

Laravel has a built-in solution: Form Requests.

Stop repeating validation and authorization logic in every method. Use the Single Responsibility Principle. A class should have only one reason to change. A controller changes when the request flow changes. It should not change just because a validation rule changes.

Run this command to create a dedicated request class: php artisan make:request StorePostRequest

Move your logic into this new class. A Form Request handles three main things:

• Authorization: Use the authorize method to decide if a user can perform an action. If it returns false, Laravel sends a 403 error automatically.

• Validation: Use the rules method to define your data requirements.

• Data Preparation: Use prepareForValidation to clean or transform data before validation runs. This is perfect for generating slugs or normalizing phone numbers.

Once you move this logic, your controller shrinks. It might look like this:

public function store(StorePostRequest $request) { $post = Post::create($request->validated()); return redirect()->route('posts.show', $post); }

That is it. Two lines.

The controller stays lean because Laravel runs the validation and authorization before the method even starts. If the data is wrong, the user gets an error immediately.

A word of caution. Do not use Form Requests for everything. If you have a tiny route with one simple field, keep the validation inline. Use Form Requests when the logic grows, repeats, or involves permissions.

Also, do not put business logic in a Form Request. Calculations and database updates belong in a Service layer.

Find your messiest controller today. Extract the validation into a Form Request. Watch it shrink.

What is the biggest store method you have ever seen? Tell me in the comments.

Source: https://dev.to/denisgusto1/seu-controller-ta-fazendo-o-trabalho-do-form-request-e-ele-nao-devia-512o