laravel 调用未定义的方法 Illuminate\Foundation\Application::bindShared()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31250211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:03:51  来源:igfitidea点击:

Call to undefined method Illuminate\Foundation\Application::bindShared()

laravellaravel-5composer-php

提问by panthro

I've just upgraded Laravel from 5.0 to 5.1.

我刚刚将 Laravel 从 5.0 升级到 5.1。

I get this error:

我收到此错误:

Call to undefined method Illuminate\Foundation\Application::bindShared()

So after some searching I need to change bindShared to a singleton.

因此,经过一番搜索后,我需要将 bindShared 更改为单例。

I can do this in vendor/illuminate/html/HtmlServiceProvider.php

我可以在 vendor/illuminate/html/HtmlServiceProvider.php 中执行此操作

The issue is, what happens when another dev works on the project and performs a composer install, or I deploy to a server.

问题是,当另一个开发人员在该项目上工作并执行 Composer 安装或我部署到服务器时会发生什么。

How can I persist changes to files in the vendor folder?

如何保留对供应商文件夹中文件的更改?

回答by alexrussell

Okay based on your comment I see your issue (I should have noticed it sooner as you do mention the HTML component in your question.

好的,根据您的评论,我看到了您的问题(当您在问题中提到 HTML 组件时,我应该早点注意到它。

The illuminate/htmlcomponent is no longer part of Laravel proper, and hasn't yet been updated to conform to 5.1 standards. In fact, I'm pretty sure it is now officially abandoned by Taylor.

illuminate/html组件不再是 Laravel 的一部分,尚未更新以符合 5.1 标准。事实上,我很确定它现在已经被泰勒正式放弃了。

However, you can replace the illuminate/htmlrequirement with laravelcollective/html- that's the official community takeover of illuminate/html and should be a drop-in replacement.

但是,您可以illuminate/html使用laravelcollective/html替换该要求- 这是 illuminate/html 的官方社区接管,应该是直接替换。

No having to mess with stuff in vendor!

不必弄乱里面的东西vendor

回答by Md. Shafiqur Rahman

Illuminate/htmlis abandoned. Use Collective/htmlinstead.

Illuminate/html被遗弃。使用Collective/html来代替。

To install it use the following

要安装它,请使用以下命令

composer require "laravelcollective/html":"^5.2.0"

Then in app/app.php file change/add as following
for providers

然后在 app/app.php 文件中
为提供者更改/添加如下

Collective\Html\HtmlServiceProvider::class

and for aliases

和别名

'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

回答by Igor Parra

The following Laravel features have been deprecated and will be removed entirely with the release of Laravel 5.2 in December 2015: ...

The service container's bindShared method has been deprecated in favor of the singleton method. ...

以下 Laravel 功能已被弃用,并将在 2015 年 12 月发布的 Laravel 5.2 中完全删除:...

服务容器的 bindShared 方法已被弃用,取而代之的是单例方法。...

ref: https://laravel.com/docs/5.1/upgrade

参考:https: //laravel.com/docs/5.1/upgrade



So, for example, starting from L5.1 you can safely change:

因此,例如,从 L5.1 开始,您可以安全地更改:

    $this->app->bindShared(UserObserver::class, function ()
    {
        // ... 
    });

to:

到:

    $this->app->singleton(UserObserver::class, function ()
    {
        // ... 
    });

回答by Amit

I am Rails developer & new to laravel & its just my first day and got stuck in this Form Builder issue. I have gone through many discussions and posts but got my solution on https://laravelcollective.com/docs/5.0/htmlTo use blade form builder (Form::open) we need to change our composer.jsonand add "laravelcollective/html": "~5.0"in the require block. Then run composer updatebecause then only new dependencies will be available to your project. Now add 'Collective\Html\HtmlServiceProvider', inside config/app.php inside providers block also you need to add

我是 Rails 开发人员和 laravel 新手,这只是我的第一天,并陷入了这个 Form Builder 问题。我经历了很多讨论和帖子,但在https://laravelcollective.com/docs/5.0/html上找到了我的解决方案 要使用刀片表单构建器(Form::open),我们需要更改我们的composer.json并添加"laravelcollective/html": "~5.0"需要堵塞。然后运行composer update因为只有新的依赖项将可用于您的项目。现在添加'Collective\Html\HtmlServiceProvider',在 config/app.php 里面的 providers 块中也需要添加

'aliases' => [
    // ...
      'Form' => 'Collective\Html\FormFacade',
      'Html' => 'Collective\Html\HtmlFacade',
    // ...
  ],

inside config/app.php in aliases block.

在别名块中的 config/app.php 中。

run php artisan serve Enjoy Form builder with blade engine.

运行 php artisan serve 使用刀片引擎享受表单构建器。

回答by Jayant Pandey

This issue comes due to bindShared() method , just change it in to singleton()

这个问题是由 bindShared() 方法引起的,只需将其更改为 singleton()

file is located here: /projectname/vendor/illuminate/html/HtmlServiceProvider.php

文件位于:/projectname/vendor/illuminate/html/HtmlServiceProvider.php

change on line no : 36 and 49

在线更改编号:36 和 49