Laravel踩坑笔记——illuminate/html被抛弃
起因
在使用如下代码的时候发生报错
{!! Form::open() !!}
错误信息
[Symfony\Component\Debug\Exception\FatalErrorException] Call to undefined method Illuminate\Foundation\Application::bindShared()
原因
在Stack Overflow找到相关问题(Call to undefined method Illuminate\Foundation\Application::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中的 'Illuminate\Html\HtmlServiceProvider' aliases中的 'Form' => 'Illuminate\Html\FormFacade', 'HTML' => 'Illuminate\Html\HtmlFacade
移除illuminate/html包
composer remove illuminate/html composer update
从官方文档我们可以看到,代替的包为laravelcollective/html
所以
安装laravelcollective/html
composer require laravelcollective/html
回到config/app.php
加入如下语句
providers中的 Collective\Html\HtmlServiceProvider::class, aliases中的 'Form'=>Collective\Html\FormFacade::class, 'Html'=>Collective\Html\HtmlFacade::class,
问题解决
另外
1.本文写作时使用Laravel版本5.4,PHP版本5.6
2.附上Laravel关于Forms & HTML的文档(基于5.4)——laravelcollective/html