mardi 12 février 2019

Laravel 5.2 custom validator not giving error

I get no errors when the validator fails. I have a function where I want to validate the request URL.

public function update(Request $request, RequestUser $user, $id)
    {
        $this->validate($request, [
            'integration_domain' => 'required',
        ]);
        //other stuff
    }

Below is where I have created the validator,

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \Validator::extend('integration_domain', function($attribute, $value, $parameters, $validator) {
            if((strpos($parameters->input('url'), 'localhost') !== false) || 
                (strpos($parameters->input('url'), 'http://localhost') !== false) ||  
                (strpos($parameters->input('url'), 'https://localhost') !== false) ||  
                (strpos($parameters->input('url'), '127.0.0.1') !== false) ||
                (strpos($parameters->input('url'), 'http://127.0.0.1') !== false) ||
                (strpos($parameters->input('url'), 'http://127.0.0.1') !== false))
                return false;
            return true;
        });
    }
}

I have followed this answer.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire