Last active
August 20, 2020 16:45
-
-
Save KABBOUCHI/d3b79448f17852f32998011b129cb73d to your computer and use it in GitHub Desktop.
Dry Run Laravel Form Requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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