Can someone help me as to why the code bellow does not work. I created a ServicePrvoider which runs, i register the singleton, but then when i try to use it Laravel cant find it. I believe Laravel is capable of resolving classes from use, and it works just from using app->make.
Thanks.
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Plivo\RestAPI; class PlivoServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { } /** * Register the application services. * * @return void */ public function register() { // $this->app->singleton('\App\Plivo', function ($app) { return new RestAPI( config('plivo.id'), config('plivo.token') ); }); $value = $this->app->make('\App\Plivo'); // This works $value = new \App\Plivo; // This throws a not found error } }@kjones1876, you should know difference between Laravel Container and global class..
This line resolvers '\App\Plivo' instance in laravel app(the container).
$this->app->make('\App\Plivo');
And also this line just creates new object from class if it is defined..
$value = new \App\Plivo; // This throws a not found error
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community