Download the PHP package pancake423/laravel-sfr without Composer
On this page you can find all versions of the php package pancake423/laravel-sfr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pancake423/laravel-sfr
More information about pancake423/laravel-sfr
Files in pancake423/laravel-sfr
Package laravel-sfr
Short Description Static Form Requests for Laravel: a simple, clean alternative to FormRequests.
License MIT
Informations about the package laravel-sfr
Static Form Requests for Laravel
Streamline your API request validation and ensure type safety.
Laravel form requests are powerful, but getting back validated data in an array is messy. You end up with array key strings in your controllers, which are vague and error prone.
What we want instead are nice objects with explicitly defined properties. Now your IDE knows what fields exist on your controllers, and what types they are. Happy IDE = less silly bugs = happy developer.
Note that this might not be a suitable replacement for all FormRequests, as it is just designed to streamline basic use cases. It is best suited for simple API requests.
How To Use
This project takes advantage of PHP8's Attributes to achieve simple, minimalistic code. Anyone who has worked with Livewire will find the syntax familiar.
For example, here's what a login request might look like with SimpleFormRequest:
and here's what the corresponding controller might look like:
Caveats
Can't handle all use cases for FormRequests (yet?). Nested fields won't work, and array data might not behave well.
Additionally, if you use extra validation steps (prepareForValidation() or similar), those won't work. Other keys
defined on a FormRequest, like $redirect, also won't work. But, it makes the easy cases really pretty :)
How To Install
Note that this library requires Laravel. If you're not using Laravel, it will not work!