Skip to main content

Moving Validation to Form Request Class

Lesson 02/30 4:41
Autoplay

Comments & Discussion

O
oluchristian ✓ Link copied!

please can we get a link to the project file you are working with in this course so that following along can be moe efficient?

PK
Povilas Korop ✓ Link copied!

To be honest, I didn't save any repositories for this course because they were all separate small experiments, relatively easy to re-create if needed.

TR
Tobias Rohde ✓ Link copied!

How can I use form request classes when I have different rules depending on the state of an object?

A simple example might be a post in a blog. We have three properties: title, text and state. If the state is "draft" only the title is required. If state is "published" title and text should be required.

PK
Povilas Korop ✓ Link copied!

You can use rules like required_when or required_if from Laravel, and/or you can have custom validation rules built which would access all the data from the request. Adding on my to-do list to write an article about this specific example, in a few weeks.

PK
Povilas Korop ✓ Link copied!
M
marcelo-kazalukian ✓ Link copied!

Hello. Can I reuse that form request in the Web, Api and console routes? I thought that form request only work for Web route.

M
Modestas ✓ Link copied!

Form request works with any request. It doesn't matter if it's web, API or console route. As long as it is properly configured - it does work (and by configured, I mean that the request is properly made)

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.