我需要在扩展 LaravelValidator 的自定义 Laravel Validator 类中的某些验证方法中访问 Db 存储库。如何得到它?
我的类构造函数:
<?php namespace Pongo\Cms\Support\Validators;
use Illuminate\Validation\Validator as LaravelValidator;
use Pongo\Cms\Support\Repositories\PageRepositoryInterface as Page;
use Pongo\Cms\Support\Repositories\ElementRepositoryInterface as Element;
class PongoValidator extends LaravelValidator {
/**
* Class constructor
* @param Page $page
* @param Element $element
*/
public function __construct($translator, $data, $rules, $messages, Page $page, Element $element)
{
$this->page = $page;
$this->element = $element;
}
[...]
和我的验证器解析器(在 Laravel 文档中):
<?php
/**
* Instantiate CustomValidator class
*/
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new Pongo\Cms\Support\Validators\PongoValidator($translator, $data, $rules, $messages);
});
如何让它发挥作用?谢谢