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();

http://laravel.io/bin/e3d9x

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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -