vendredi 25 décembre 2015

Custom Request Validator in Laravel

I just want to validate API requests using laravel custom Request Handler. For this I have created a RegisterRequest, with the following content.

<?php

namespace App\Http\Requests\Api\Auth;

use App\Http\Requests\Request;

class RegisterRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'required'
        ];
    }
}

And, I want it to use in AuthController as:

use App\Http\Requests\Api\Auth\RegisterRequest;

    public function postRegister(RegisterRequest $request)
    {
        dd($request->all());
    }

But, neither the validation nor the request parameters are shown in the respose. All the routing are working fine, but the query paremeters are empty. Any help will be appriciated.

Version: Laravel: 5.1

I want to let laravel handle all request parameters and say API whether the request is made successful or with errors.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire