vendredi 4 septembre 2015

Laravel 5 Custom Validator resolver not found

Hi Guys I would like to register my new CustomValidator class. This contains some validation for a mobile number I created this class

<?php

// This class is located in App\Validator
use Illuminate\Validation\Validator;

class CustomValidator extends Validator {

    public function validateIsKyc($attribute, $value, $parameters)
    {
        return $value == 'is_kyc';
    }


}

Now in my AppServiceProvider here's my code for loading that class

<?php

namespace App\Providers;


use Illuminate\Validation\Validator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
    */
    public function boot()
    {       
        Validator::resolver(function($translator, $data, $rules, $messages)
        {
            return new CustomValidator($translator, $data, $rules, $messages);
        });

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

And on my request I tried using the custom validation like so

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

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

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

But I get this error

FatalErrorException in AppServiceProvider.php line 23: Call to undefined method Illuminate\Validation\Validator::resolver()

Don't know what went wrong any idea please...



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

Aucun commentaire:

Enregistrer un commentaire