Skip to content

Instantly share code, notes, and snippets.

@KABBOUCHI
Last active August 20, 2020 16:45
Show Gist options
  • Save KABBOUCHI/d3b79448f17852f32998011b129cb73d to your computer and use it in GitHub Desktop.
Save KABBOUCHI/d3b79448f17852f32998011b129cb73d to your computer and use it in GitHub Desktop.
Dry Run Laravel Form Requests
<?php
namespace App\Http\Requests;
trait canDryRun
{
/**
* Validate the class instance.
*
* @return void
*/
public function validateResolved()
{
parent::validateResolved();
if (request()->has('dry-run')) {
abort(204);
}
}
}
/** Usage
class CreatePostRequest extends FormRequest
{
use canDryRun;
...
-------------------------
POST /api/posts?dry-run
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment