Download the PHP package dive-be/laravel-dry-requests without Composer
On this page you can find all versions of the php package dive-be/laravel-dry-requests. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dive-be/laravel-dry-requests
More information about dive-be/laravel-dry-requests
Files in dive-be/laravel-dry-requests
Package laravel-dry-requests
Short Description Dry run your Laravel requests
License MIT
Homepage https://github.com/dive-be/laravel-dry-requests
Informations about the package laravel-dry-requests
Warning two months after the release of our package, Taylor Otwell announced an almost identical functionality as a core package. Since this package has pretty much been made obsolete, we have decided to stop maintaining it.
So, please consider migrating to Laravel Precognition.
X-Dry-Run your requests
This package allows you to check if your requests would pass validation if you executed them normally.
The Laravel equivalent of --dry-run
in various CLI tools, or what some devs call "preflight requests".
🚀 Hit the endpoint as users are entering information on the form to provide real-time feedback with 100% accuracy.
🚀 Validate only a subset of data of a multi-step form to guarantee success when the form is eventually submitted.
Showcase
What problem does this package solve?
A traditional approach to validating user input in JavaScript applications (Inertia / SPA / Mobile) is using a library such as yup to do the heavy lifting and delegating complex business validations to the server.
However, the client-side can never be trusted, so you can't simply omit the validation rules that ran on the front-end. This means that validation has to live in 2 distinct places and you will have to keep them in sync. This is very tedious and wasteful, so this is where this package comes into play.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Behavior
💡 Controller
logic is not executed after a successful validation attempt. 200 OK
is returned upon a successful dry run.
💡 Only present fields are validated to ensure good UX. Other fields are skipped using the sometimes
rule.
This means that you are responsible for only sending the relevant fields for validating e.g. a step of a multi-step wizard.
Usage
Assume the following endpoint: POST /users
and Controller
.
Option 1 - using FormRequest
s
Controller
injecting a StoreUserRequest
:
Add the DryRunnable
trait to your FormRequest
:
That's it 😎.
Option 2 - using validate
method on the Request
object
You don't have to do anything at all 🤙.
Front-end execution
Now, hit the endpoint from the client-side like you normally would.
But with the added X-Dry-Run
header.
Inertia.js example
Fine-tuning Dry Validations: AllFailures
/ FirstFailure
- The default validation behavior for dry requests is halting validation as soon as an error is found. This is especially useful when handling async validation for a single field.
- The other option is to keep validating even if an error is encountered. This is especially useful for multi-step forms.
You can alter this behavior on 3 distinct levels.
- Change
first
toall
(or vice versa) in thedry-request
config file. This will apply to all of your requests. -
FormRequest only - Use the
Dive\DryRequests\Dry
attribute along withDive\DryRequests\Validation
on therules
method to force a specificValidation
behavior for a particularFormRequest
. - Dictate the behavior on the fly from the front-end using the
X-Dry-Run
header. Valid values:all
,first
.
Note: the header value will be ignored if you have explicitly set a validation behavior on the FormRequest
using the Dry
attribute.
Conflicting FormRequest
methods
The package makes use of the available methods passedValidation
and withValidator
available on FormRequest
classes to enable its behavior.
If you define these in your own requests, you must call the "dry" methods manually:
Testing
Upgrading
Please see UPGRADING for details.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email oss@dive.be instead of using the issue tracker.
Credits
- Muhammed Sari
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-dry-requests with dependencies
dive-be/php-enum-utils Version ^1.1
dive-be/php-utils Version ^0.1.0
laravel/framework Version ^10.0