laravel - Statically retrieving rules out of Laracasts\Validation classes -
i have following form validation class:
class edititemsform extends laracasts\validation\formvalidator { protected $rules = [ 'name' => 'required|alpha' ]; } i need use value in $rules populate former::withrules() can it's thing.
i try adding static getrules method such can former::withrules(edititemsform::getrules()) protected value, requires creating new instance of edititemsform parent fromvalidator requires laracasts\validation\factoryinterface first constructor argument.
example:
public static function getrules() { return with(new self(null))->rules; } call me spoiled, have never had deal before. used laravel doing it's magical dependency injection in background when input values passed controller.
how can value of $rules in case without having have instance of factoryinterface, or how dynamically create instance pass in getrules?
have tried ioc container of laravel instantiate edititemsform class. resolve dependencies you.
app::make('edititemsform'); a quote laravel docs
the ioc container powerful enough resolve classes without configuration @ in many scenarios. example:
class foobar { public function __construct(baz $baz) { $this->baz = $baz; } } $foobar = app::make('foobar');
Comments
Post a Comment