Last week, I shared a tip about using a trait to communicate intent in a form request with no rules. Today, I want to share some reasons why you might have such a form request in the first place.
The biggest one, by far for us, is authorization logic. There are other places to do authorization, but sometimes it makes the most sense to do it on the form request.
Looking through some recent projects, I also saw examples where we used a form request without validation rules to define a helper method related to the request.
For example, one project used Socialite to authenticate users with SAML2 and a third-party identity provider. There was a bunch of config-related setup to do, and it was convenient to encapsulate on a Saml2Request
.
In my experience, form requests are an underutilized feature in Laravel projects. Maybe this will spark some ideas for you.
Here to help,
Joel
P.S. Speaking of underutilized features, do you want to get more out of your validation rules?