1. 程式人生 > >Laravel踩坑筆記——illuminate/html被拋棄

Laravel踩坑筆記——illuminate/html被拋棄

mina one lec define 文檔 onf acad lar require

起因

在使用如下代碼的時候發生報錯

{!! 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

Laravel踩坑筆記——illuminate/html被拋棄