Php 使用breadcrumbs包时调用undefined方法Illumb\Foundation\Application::share()

Php 使用breadcrumbs包时调用undefined方法Illumb\Foundation\Application::share(),php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,今天,我想使用带有laravel5.4的软件包。我将它与laravel5.3一起使用,没有任何问题,所有的事情都很好 但在运行应用程序时,我遇到了以下错误: FatalErrorException in ServiceProvider.php line 34: Call to undefined method Illuminate\Foundation\Application::share() 我搜索了一下,发现从laravel 5.4开始,share已被删除。我必须使用单例 但是当我这样做时

今天,我想使用带有laravel5.4的软件包。我将它与laravel5.3一起使用,没有任何问题,所有的事情都很好

但在运行应用程序时,我遇到了以下错误:

FatalErrorException in ServiceProvider.php line 34:
Call to undefined method Illuminate\Foundation\Application::share()
我搜索了一下,发现从laravel 5.4开始,share已被删除。我必须使用
单例

但是当我这样做时,
ServiceProvider.php
中的更改如下:

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;
        });
    }
ErrorException in Container.php line 1057:
Illegal offset type in unset
我又犯了一个错误。像这样:

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;
        });
    }
ErrorException in Container.php line 1057:
Illegal offset type in unset
我不知道是什么问题。有人能帮我吗

更新:


我找到了解决办法

第一个问题是,singleton实例希望绑定一个类作为第一个参数,在本例中是
“breadcrumbs”

第二个问题是,您不需要显式声明singleton实例的数组键。这就是它的外观:

$this->app->singleton('breadcrumbs', function($app)
下一个问题是您正在使用的软件包已被弃用。开发者将不再维护它

最后一个问题是您使用的是版本
<3.0.2
。因此,将
composer.json
中的版本更改为
3.0.2
,然后安装该版本,这样就不需要修改任何文件