dimanche 17 janvier 2016

Input validation and fomatting in Laravel 5.1 using FormRequest

I have Model Leave in my laravel 5.1 application. I want to do following things

  1. Validate input data using Laravel FormRequest
  2. On successful validation format the input field for processing (eg. parsing date input string to Carbon object for processing)
  3. This processing is to be done before calling controller action, (ie controller action should receive formatted data)

I have a LeaveRequest class to do following things.

  1. rules() method to provide validation rule array.
  2. overridden method all() to format the input data.

Problems 1. all() method is called before validation 2. I want to validate unformatted data (as is submitted through form) first and on successful validation format the same. 3. I don't want to call any function from controller to format data it should be handled by LeaveRequest class.

What approach should I use for this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire