Class not found after adding service provider class

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.

+4
source share
1 answer

"app/Extension" composer.json autoload > classmap, :

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/Extension"
    ]
} 

, "app/Extension"

composer dump-autoload
+3

All Articles