起因
在使用如下代码的时候发生报错
{!! Form::open() !!}
错误信息
[SymfonyComponentDebugExceptionFatalErrorException] Call to undefined method IlluminateFoundationApplication::bindShared()
原因
在Stack Overflow找到相关问题(Call to undefined method IlluminateFoundationApplication::bindShared())
由大家的回答和官方文档(Upgrade Guide)中可以知道,bindShared已经被抛弃
The actual issue is that L 5.1 has depreciated bindShared and illuminate still uses it. From the L5 upgrade page: The service container's
bindShared method has been deprecated in favor of the singleton method. --panthro
解决
打开config/app.php
移除以下句
providers中的 'IlluminateHtmlHtmlServiceProvider' aliases中的 'Form' => 'IlluminateHtmlFormFacade', 'HTML' => 'IlluminateHtmlHtmlFacade
移除illuminate/html包
composer remove illuminate/html composer update
从官方文档我们可以看到,代替的包为laravelcollective/html
所以
安装laravelcollective/html
composer require laravelcollective/html
回到config/app.php
加入如下语句
providers中的 CollectiveHtmlHtmlServiceProvider::class, aliases中的 'Form'=>CollectiveHtmlFormFacade::class, 'Html'=>CollectiveHtmlHtmlFacade::class,
问题解决
另外
1.本文写作时使用Laravel版本5.4,PHP版本5.6
2.附上Laravel关于Forms & HTML的文档(基于5.4)——laravelcollective/html