php - Lumen (Laravel) include library & use class in Controller -
i have question! have library, whenever need call, i'll include & new class()
link below.
now, want include use lumen framework & call inton controller, how register service, class in lumen make comfortable when needing, call new filemaker();
thank much!
what you're looking service provider. instead of including files in controllers, , new'ing instances of class better register class within service provider , resolve object out of ioc container.
an example of how can register provider:
public function register() { $this->app->singleton('full\vendor\namespace\filemaker', function($app) { return new filemaker('someparameters'); }); }
doing way means can inject dependencies controllers , laravel, or lumen in case automatically resolve object without needing instantiate object.
for example, in controller:
public function somecontrollermethod(filemaker $filemaker) { // $filemaker instance available use }
Comments
Post a Comment