I am trying to extend the Validator class. So my text box does not return false when adding space.
I create a folder like app \ extension \ validation
Here is my CustomValidation class
<?php namespace App\Extension\Validation;
use Illuminate\Validation\Validator;
class CustomValidation extends Validator{
public function alpha_spaces($attribute, $value, $parameters)
{
if(preg_match("/^([-a-z0-9_ ])+$/i", $value))
{
return true;
}
return false;
}
}
Here is the ValidationServiceProvider class in the same folder
<?php namespace App\Extension\Validation;
use Illuminate\Support\ServiceProvider;
class ValidationServiceProvider extends ServiceProvider{
public function register(){}
public function boot()
{
$this->app->validator->resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidation($translator, $data, $rules, $messages);
});
}
}
And here is the error I get when I try to add a service provider in app.php
Class 'App\Extension\Validation\ValidationServiceProvider' not found
I have a class in the \ Extension \ Validation application as ValidationServiceProvider.php
Does anyone know why I have such a problem. I got stuck on this all day, and I need help from someone, please.
source
share