我在 composer.json 中添加了 "illuminate/html": "5.*" 并运行了 "composer update"。
- Installing illuminate/html (v5.0.0)
Loading from cache
我在网站的根目录中运行了这个命令。我在 /root/.composer... 和项目的根目录中修改了 composer.json 文件,但都没有改变。
这下载了课程,它似乎安装了。我已将以下内容添加到文件 config/app.php。
'Illuminate\Html\HtmlServiceProvider',
'Form' => 'Illuminate\Html\FormFacade',
'Html' => 'Illuminate\Html\HtmlFacade',
我想我知道出了什么问题,但我不知道如何解决它。我的安装在“/var/www/website”中。我检查了文件路径,并且 Html 文件夹不存在。
"/var/www/website/vendor/laravel/framework/src/Illuminate/Html"
我能够找到类文件,但在不同的目录中。
"/var/www/website/vendor/illuminate/html"
我手动将文件复制到 Laravel 的主Illuminate/html 文件夹中,但这也不起作用。
Form
不像 4.0 那样包含在 laravel
5.0 中,包含它的步骤:
首先通过 Composer
安装 laravelcollective/html
包。编辑项目的 composer.json
文件以要求:
"require": {
"laravelcollective/html": "~5.0"
}
接下来,从终端更新 composer
:
composer update
接下来,将您的新提供程序添加到 config/app.php
的 providers
数组中:
'providers' => [
// ...
'Collective\Html\HtmlServiceProvider',
// ...
],
最后,将两个类别名添加到 config/app.php
的 aliases
数组:
'aliases' => [
// ...
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
// ...
],
此时,Form
应该可以工作了
更新 Laravel 5.8
(2019-04-05):
在 Laravel 5.8
中,config/app.php
中的 providers
可以声明为:
Collective\Html\HtmlServiceProvider::class,
代替:
'Collective\Html\HtmlServiceProvider',
这种表示法与别名相同。
这可能不是您要寻找的答案,但我建议使用现在由社区维护的存储库 Laravel Collective Forms & HTML,因为主要存储库已被弃用。
Laravel Collective 正在更新他们的网站。如果需要,您可以view the documentation on GitHub。
只需在项目目录的终端中输入以下命令,即可根据 Laravel 版本完成安装:
composer require "laravelcollective/html"
然后在 config/app.php
中添加这些行
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
您还可以尝试在终端或命令中运行以下命令:
composer dump-auto 或 composer dump-auto -o php artisan cache:clear php artisan config:clear
以上对我有用。
Laravel 5.2 对此进行了更新。请注意,这与上面指出的格式略有不同。
首先通过 Composer 安装这个包。编辑项目的 composer.json 文件以要求 laravelcollective/html。
"require": {
"laravelcollective/html": "5.2.*"
}
接下来,从终端更新 Composer:
composer update
接下来,将您的新提供者添加到 config/app.php 的提供者数组中:
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
最后,在 config/app.php 的 aliases 数组中添加两个类别名:
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
进行此更新后,此代码在 Laravel 5.2 的新安装中为我工作:
{!! Form::open(array('url' => 'foo/bar')) !!}
//
{!! Form::close() !!}
我在这里得到了这个信息:https://laravelcollective.com/docs/5.2/html
首先通过 Composer 安装这个包。从终端运行以下命令:
composer require "laravelcollective/html":"^5.3.0"
接下来,将您的新提供者添加到 config/app.php 的提供者数组中:
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
最后,在 config/app.php 的 aliases 数组中添加两个类别名:
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
SRC:
https://laravelcollective.com/docs/5.3/html
在 Laravel 版本 - 4 中,HTML 和 Form 存在,但现在不存在。
为什么:
唯一的原因是他们收集了一些用户需求并且他们希望它更轻量级,因此他们删除了它,因为用户可以手动添加它。
如何在 Laravel 5.2 或 5.3 中添加 HTML 和表单:
对于 5.2:
转到Laravel Collective site,安装过程已经演示了它们。
与 5.2 一样:在命令行上,运行命令
composer require "laravelcollective/html":"^5.2.0"
然后,在 config/app.php 中的提供程序数组中。最后使用逗号(,)添加此行:
Collective\Html\HtmlServiceProvider::class,
为了使用 HTML 和 FORM 文本,我们需要在 config/app.php 的 aliases 数组中为它们设置别名。在最后添加两行
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
对于 5.3:
只需运行命令
composer require "laravelcollective/html":"^5.3.0"
其余的过程就像 5.2。
然后你可以在你的项目中使用 Laravel Form 和其他 HTML 链接。为此,请遵循此文档:
5.2: https://laravelcollective.com/docs/5.2/html
5.3: https://laravelcollective.com/docs/5.3/html
演示代码:
要打开表单,请打开和关闭标签:
{!! Form::open(['url' => 'foo/bar']) !!}
{!! Form::close() !!}
以及使用 Bootstrap 表单控件类和其他用途创建标签和输入文本:
{!! Form::label('title', 'Post Title') !!}
{!! Form::text('title', null, array('class' => 'form-control')) !!}
更多信息,请使用文档 https://laravelcollective.com/。
使用 Form
,而不是 form
。大小写很重要。
我已经尝试了一切,但只有这有帮助:
php artisan route:clear
php artisan cache:clear