vendredi 19 avril 2019

Laravel 5.7. Route model binding validation

I'd like to use sweet Laravel model binding and then run some complex validation checks on the model itself.

Something like

Route::post('/do-something/{something}', 'SomeController@store');

and

$request->validate([
    'order' => [
        new MyFirstVeryComplexRule,
        new MySecondVeryComplexRule,
        new MyThirdVeryComplexRule,
        //...
    ],
]);

I assume, that $value passed to each rule will be an instance of App\Something class.

Is is possible to achieve that?

The closest option I can think of is to pass id of a model and then run App\Some::find($value) in each rule instance, but this kills the performance and is not scalable.

Answer

No, this is not possible because of x,y,z, try a,b,c

will also be accepted.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire