You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application that uses FormRequest classes extensively, in order to ensure that authorization and validation are done. Some of these requests use traits and/or inheritance to include common parameters. (For example, reports can be filtered by specific data points, but all reports can also be filtered by date range and location ID, so they all include FilteredPermittedDateRangeReportRequest which adds the common start and end date validations and authorization/validation for the chosen location IDs.
I also like the idea of Single Action Controllers for cleanliness, because it allows each of the report types to be a self-contained file.
But using these two techniques together means I still have two files - one for the authorization and validation, and the other for the execution.
I'm thinking of creating a common SingleFormController something like this (pseudocode):
class MyReportController extends SingleFormController
{
protectedfunctionauthorize(Request$request): bool
{
// Same as the `FormRequest::authorize` method
}
protectedfunctionrules(Request$request): array
{
// Same as the `FormRequest::rules` method
}
protectedfunctionhandle(Request$request)
{
// If authorization and validation both pass, execute the code
}
}
However, this seems to me like it's something the framework should be able to handle already, because 99% of the functionality is already there. It feels like I'd be reinventing the wheel to implement this myself. There's so much that happens behind the scenes when processing a FormRequest, and I'm concerned that my implementation will need a lot of work to maintain the same behavior as I have with just using a form request implementation with a single action controller.
Have I missed a way to do this that already exists? Or should I implement it? Or is it not worth doing?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have an application that uses
FormRequest
classes extensively, in order to ensure that authorization and validation are done. Some of these requests use traits and/or inheritance to include common parameters. (For example, reports can be filtered by specific data points, but all reports can also be filtered by date range and location ID, so they all includeFilteredPermittedDateRangeReportRequest
which adds the commonstart
andend
date validations and authorization/validation for the chosenlocation
IDs.I also like the idea of Single Action Controllers for cleanliness, because it allows each of the report types to be a self-contained file.
But using these two techniques together means I still have two files - one for the authorization and validation, and the other for the execution.
I'm thinking of creating a common
SingleFormController
something like this (pseudocode):That can be used like this:
However, this seems to me like it's something the framework should be able to handle already, because 99% of the functionality is already there. It feels like I'd be reinventing the wheel to implement this myself. There's so much that happens behind the scenes when processing a
FormRequest
, and I'm concerned that my implementation will need a lot of work to maintain the same behavior as I have with just using a form request implementation with a single action controller.Have I missed a way to do this that already exists? Or should I implement it? Or is it not worth doing?
Beta Was this translation helpful? Give feedback.
All reactions