mercredi 4 mai 2016

Laravel 5.2 - Validation with API

I am using Laravel 5.2 for validation with a REST JSON API.

I have a UserController that extends Controller and uses the ValidatesRequests trait.

Sample code:

$this->validate($request, [
        'email'         => 'required|email',
        'password'      => 'required|min:4|max:72',
        'identifier'    => 'required|min:4|max:36',
        'role'          => 'required|integer|exists:role,id',
    ]);

This throws an exception, so in my Exceptions/Handler.php I have this code:

    public function render($request, Exception $e)
    {
       return response()->json([
           'responseCode'  => 1,
           'responseTxt'   => $e->getMessage(),
       ], 400);
    }

However, when validating responseTxt is always:

Array
(
   [responseCode] => 1
   [responseTxt] => The given data failed to pass validation.
)

I have used Laravel 4.2 in the past and remember the validation errors providing more detail about what failed to validate.

How can I know which field failed validation and why?



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

Aucun commentaire:

Enregistrer un commentaire