lundi 19 octobre 2020

Class does not exist exception if I don't provide full path to my class in Laravel validation extension

I am using Laravel 5.8 and attempting to set up a custom validation extension.

  • I have created a class GroupValidator containing a validate function.
  • I have created a ValidationServiceProvider with the following code:
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
use App\Classes\GroupValidator;

class ValidationExtensionServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        Validator::extend('valid_parent_id', 'GroupValidator@validate');
    }
}

When my validation triggers I get a Class GroupValidator does not exist exception. However if I specify the full path to my class in the extend function call like so:

Validator::extend('valid_parent_id', 'App\Classes\GroupValidator@validate');

then everything works fine.

Is there some way I can set this up so that I don't have to include the full path to my class?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3o83Uav
via IFTTT

Aucun commentaire:

Enregistrer un commentaire