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
When casting enums in a Form Request, only the data payload in the Request instance is getting cast. So if following best practice and getting the data with the validated method in a controller, the original pre-cast data will be returned.
class Controller
{
publicfunctionindex(MyFormRequest$request)
{
$request->validated()); // Doesn't return cast data$request->get('status'); // Return cast data
}
}
As a fix, I created an enhanced TransformsEnums trait implementing the following method:
Do you think that this is something that could be added to the package?
I could draft a PR on this, but given the native enum support on PHP 8.1 I wanted to make sure you would continue the maintenance of laravel-enum before working on it.
Cheers.
The text was updated successfully, but these errors were encountered:
Hello 👋,
When casting enums in a Form Request, only the data payload in the Request instance is getting cast. So if following best practice and getting the data with the
validated
method in a controller, the original pre-cast data will be returned.As a fix, I created an enhanced
TransformsEnums
trait implementing the following method:Do you think that this is something that could be added to the package?
I could draft a PR on this, but given the native enum support on PHP 8.1 I wanted to make sure you would continue the maintenance of laravel-enum before working on it.
Cheers.
The text was updated successfully, but these errors were encountered: