vendredi 26 février 2016

Laravel Validation - Best practices with Request classes

Laravel (currently 5.2) says

For more complex validation scenarios, you may wish to create a "form request". Form requests are custom request classes that contain validation logic.

I have this all implemented, but now I need to import some data that is not coming through HTTP, but from an uploaded document.

Is there an easy way to manually validate data using the rules set in the Request classes, or is there a standardised Laravel way of separating the rules so that they can be used in multiple places?

Note: I have different rules for storing and updating etc

One approach I thought of was to create some static properties on my models, eg. User::$storeRules, and then I can return this array in my Request classes, and them manually using the Validator class elsewhere.

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1oEGjxZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire