Laravel 5.2 What goes in facade getFacadeAccessor return Laravel 5.2 What goes in facade getFacadeAccessor return php php

Laravel 5.2 What goes in facade getFacadeAccessor return


First, your service provider should be in the App\Providers namespace, and should extend ServiceProvider. So it will look like this:

<?phpnamespace App\Providers;use Illuminate\Support\ServiceProvider;use Jbm\Helpers\ReportGenerator;class ReportGeneratorServiceProvider extends ServiceProvider{    public function register()    {        $this->app->bind('Jbm\Helpers\Contracts\ReportGeneratorContract', function($app){            return new ReportGenerator();        });    }    }

After that, the facade should be in the App\Facades namespace, and the getFacadeAccessor() method should return the class name of your service provider:

<?phpnamespace App\Facades;use Illuminate\Support\Facades\Facade;class ReportGenerator extends Facade {    protected static function getFacadeAccessor()     {         return App\Providers\ReportGeneratorServiceProvider::class;    }}

Now, let's add the service provider and facade to the app:

// config/app.php'providers' => [    App\Providers\ReportGeneratorServiceProvider::class,]'aliases' => [    'ReportGenerator' => App\Facades\ReportGenerator::class,]


getFacadeAccessor should return a string that your container "knows about". That means something that is registered via a Provider.

You add your facade and an alias to app.php to be able to access something your registered statically.

So when you call YourFacadeAlias::doSomething(); laravel detects YourFacaseAlias, sees what is returned from getFacadeAccessor and uses that result to return an object associated with it from container.

Since both your facade and helper are called "ReportGenerator" the problem might be with both of them. But I think you should first check your app.php to see if you set it right. And then make sure your getFacadeAccessor and binded values match.