如何修复Reflection异常类验证器不存在错误

时间:2014-09-25 17:58:53

标签: php class laravel service-provider laravel-validation

我最近正在处理一些代码而且我收到了这个错误:第20行上没有反射异常类验证器。

这是出现错误的最后一批代码,是桌面服务提供商:

 /**
 * Register bindings
 *
 * @return void
 */
public function register()
{
    $this->repositories();

    $this->app->bind('\Desk\Forms\MessageForm', function($app) {
        $validator = $app['validator']->make([], []);  (line 20)
        return new \Desk\Forms\MessageForm($validator);
    });
}

/**
 * Register Repositories
 */
protected function repositories()
{

    $this->app->bindShared('\Desk\Repositories\MessageRepository', function($app) {
        $record = new \Desk\Records\MessageRecord;
        return new \Desk\Repositories\MessageRepository($record);
    });
}

服务提供商:

/**
 * Register bindings
 *
 * @return void
 */
public function register()
{
    $this->registerSupport();
}

控制器:

protected $messageForm;

public function __construct(MessageForm $messageForm, MessageRepository $messageRepository,
  MessageRecord $messageRecord)
{
    $this->messageForm = $messageForm;
    $this->messageRepository = $messageRepository;
    $this->messageRecord = $messageRecord;
}

/**
 * Display a listing of the resource.
 * GET /messages
 *
 * @return Response
 */
public function index()
{
    return View::make('message.create');
}

的app.config

 'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    'Illuminate\Cache\CacheServiceProvider',
    'Illuminate\Session\CommandsServiceProvider',
    'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
    'Illuminate\Routing\ControllerServiceProvider',
    'Illuminate\Cookie\CookieServiceProvider',
    'Illuminate\Database\DatabaseServiceProvider',
    'Illuminate\Encryption\EncryptionServiceProvider',
    'Illuminate\Filesystem\FilesystemServiceProvider',
    'Illuminate\Hashing\HashServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',
    'Illuminate\Log\LogServiceProvider',
    'Illuminate\Mail\MailServiceProvider',
    'Illuminate\Database\MigrationServiceProvider',
    'Illuminate\Pagination\PaginationServiceProvider',
    'Illuminate\Queue\QueueServiceProvider',
    'Illuminate\Redis\RedisServiceProvider',
    'Illuminate\Remote\RemoteServiceProvider',
    'Illuminate\Auth\Reminders\ReminderServiceProvider',
    'Illuminate\Database\SeedServiceProvider',
    'Illuminate\Session\SessionServiceProvider',
    'Illuminate\Translation\TranslationServiceProvider',
    'Illuminate\Validation\ValidationServiceProvider',
    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Workbench\WorkbenchServiceProvider',

    'Way\Generators\GeneratorsServiceProvider',
    'Desk\ServiceProvider',
    'Desk\Auth\AuthServiceProvider',
    'Desk\Parts\PartServiceProvider',
    'Desk\Desk\Repositories\RepoServiceProvider',
    'Desk\Desk\Forms\FormServiceProvider',
    'Desk\Desk\DeskServiceProvider',

1 个答案:

答案 0 :(得分:1)

这似乎是您的自定义提供程序的代码。您应该在providers文件的app/config/app.php部分的末尾添加它,并在'Illuminate\Validation\ValidationServiceProvider'之后定义,因为此处$validator已创建。

正如我所说,转到app/config/app.php文件并找到以

开头的部分

'providers' => array(

现在编辑您的提供商列表,将您的提供商放在提供商列表的末尾:

'providers'       => array(

   // here all list of all default providers
   // here your custom provider
),

修改

然后你应该尝试改变:

$validator = $app->make('validator')->make([], []); 

$validator = $app['validator']->make([], []);