Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Why are Laravel validations run in the controller?

It seems Laravel has opted to validate input within the controller. This seems really strange (to me) because model-level validation has been drilled into me from the Rails documentation and Treehouse courses.

I've found a couple of packages (like this one https://github.com/JeffreyWay/Laravel-Model-Validation) which have made it possible to validate inside the model. This would better make for a 'skinny controller' but it's really just the same code elsewhere..

1 Answer

They don't have to be in the controller, in fact, I would prefer them to be a service. However, this would be more of an intermediate to advanced topic. This is the reason I am showing them in the controller to start with, then I will show you in upcoming lessons how to move them to a service.

If you would like to skip ahead and keep learning faster you should look here:

Advanced Validation as a Service

Community Forum - Topic Tag: Validation

Sweet!