I have the following Class:
<?php
namespace App\CustomClasses;
class Disqus {
protected $secretKey;
protected $publicKey;
public function __construct()
{
$this->secretKey = 'abc';
$this->publicKey = '123';
}
public function payload()
{
...
}
}
I have also created a Service Provider (simplified bellow), to bind this class to the IOC container:
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\CustomClasses\Disqus;
class DisqusServiceProvider extends ServiceProvider {
public function register()
{
$this->app->singleton('Disqus', function() {
return new Disqus();
});
}
public function boot()
{
//
}
}
And in my controller:
<?php
use App\CustomClasses\Disqus;
class ArticlesController extends Controller {
public function view(Disqus $disqus)
{
...
//$disqus = App::make('Disqus');
return View::make('articles.view', compact(array('disqus')));
}
}
The problem is that whenever I use the $disqus
variable, it is not 'generated' from the Service Provider, but the Disqus class itself.
However, when I have $disqus = App::make('Disqus');
, the variable goes through the service provider.
So my question is, since the binding exists in the Service Provider, shouldn't the $disqus
variable come from the DisqusServiceProvider rather than the Disqus class directly when I use it in my controller?
Am I missing something?
Thanks in advance for any help.