Reputation: 6612
Today, I want to use Laravel Breadcrumbs package with laravel 5.4. I used that with laravel 5.3 without any problem and all things worked fine.
But when run the application I got this error :
FatalErrorException in ServiceProvider.php line 34:
Call to undefined method Illuminate\Foundation\Application::share()
I searched for that and I found that As of laravel 5.4 share
has been removed. and I must to use the singleton
instead.
But when I did that changes In the ServiceProvider.php
like this :
public function register()
{
$this->app['breadcrumbs'] = $this->app->singleton(function($app)
{
$breadcrumbs = $this->app->make('DaveJamesMiller\Breadcrumbs\Manager');
$viewPath = __DIR__ . '/../views/';
$this->loadViewsFrom($viewPath, 'breadcrumbs');
$this->loadViewsFrom($viewPath, 'laravel-breadcrumbs'); // Backwards-compatibility with 2.x
$breadcrumbs->setView($app['config']['breadcrumbs.view']);
return $breadcrumbs;
});
}
I got another error. like this :
ErrorException in Container.php line 1057:
Illegal offset type in unset
I do not know what is problem. can anyone help me ?
Update :
I found the solution Here.
Upvotes: 3
Views: 4284
Reputation: 50787
The first problem is that the singleton instance expects a class to bind to as the first argument, which in this case is 'breadcrumbs'
.
The second problem is that you don't need to explicitly declare the array key for the singleton instance. So this is how it should look:
$this->app->singleton('breadcrumbs', function($app)
The next problem is that the package you're using has been abandoned
. The developer will no longer maintain it.
The final problem is that you're using a version < 3.0.2
. So change the version in your composer.json
to 3.0.2
and then install that, then you shouldn't need to be modifying any files.
Upvotes: 3