Support the ongoing development of Laravel.io →
posted 9 years ago
IOC

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 } }
Last updated 3 years ago.
0

@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
Last updated 9 years ago.
0

@muratodunc I have apparently greatly miss understood how im meant to using containers. Thanks.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

kjones1876 kjones1876 Joined 19 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.