Courses

How to Structure Laravel 9 Projects

Moving Validation to Form Request Class

avatar

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?

👍 1
avatar

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.

avatar

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.

avatar

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.

avatar

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

avatar

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)