R
R
Romi2021-10-14 11:35:14
Laravel
Romi, 2021-10-14 11:35:14

Where in Laravel is it better to validate incoming data - in the controller or make a custom Request for the controller, or Middleware?

subject :)

What approach will be the best in terms of OOP and everything else?

Or to take out in a separate service class?

Or something else?

How right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jazzus, 2021-10-14
@romicohen

Validation is usually what? Sheet) Therefore, your Form Request. Writing php artisan make:request and then importing into ide is literally seconds of time. But in this class you can do a lot of things. For example, prepareForValidation, messages, logic with its own rules, and all this will be in one place. Pushing validation into middleware or into your own classes in Laravel is a perversion.

I
Ipatiev, 2021-10-14
@Fockker

In fact, Lara ALREADY has this very separate service - Illuminate\Http\Request , which is designed to validate incoming data.

N
NubasLol, 2021-10-14
@NubasLol

Good point about validation
https://github.com/adelf/acwa_book_ru/blob/master/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question