ChatGPT解决这个技术问题 Extra ChatGPT

未找到 Laravel 5 类“表单”

我在 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 文件夹中,但这也不起作用。


P
Pedro Lobito

Form 不像 4.0 那样包含在 laravel 5.0 中,包含它的步骤:

首先通过 Composer 安装 laravelcollective/html 包。编辑项目的 composer.json 文件以要求:

"require": {
    "laravelcollective/html": "~5.0"
}

接下来,从终端更新 composer

composer update

接下来,将您的新提供程序添加到 config/app.phpproviders 数组中:

'providers' => [
  // ...
  'Collective\Html\HtmlServiceProvider',
  // ...
],

最后,将两个类别名添加到 config/app.phpaliases 数组:

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

此时,Form 应该可以工作了

Source

更新 Laravel 5.8 (2019-04-05):

Laravel 5.8 中,config/app.php 中的 providers 可以声明为:

Collective\Html\HtmlServiceProvider::class,

代替:

'Collective\Html\HtmlServiceProvider',

这种表示法与别名相同。


SRC 链接已更新。 laravelcollective.com/docs/5.3/html 从 5.0 到 5.3,他们更改了提供程序和别名部分。 Collective\Html\HtmlServiceProvider::class,用于提供者,然后是 'Form' => Collective\Html\FormFacade::class, 和 'Html' => Collective\Html\HtmlFacade::class,用于别名。
为什么在 laravel 文档中没有明确说明默认情况下不包含相当基本的组件。
P
Peter Mortensen

这可能不是您要寻找的答案,但我建议使用现在由社区维护的存储库 Laravel Collective Forms & HTML,因为主要存储库已被弃用。

Laravel Collective 正在更新他们的网站。如果需要,您可以view the documentation on GitHub


知道为什么这在 v5 中被删除了吗?
似乎他们想让它更轻量级,让人们只在需要时添加东西。
他们在升级指南或其他地方注意到了吗?没看到。
谢谢不知道这个新的 laravel 并且它仍然在主要文档中所以我不知道这不在 v5 中。
P
Peter Mortensen

只需在项目目录的终端中输入以下命令,即可根据 Laravel 版本完成安装:

composer require "laravelcollective/html"

然后在 config/app.php 中添加这些行

'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
],

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

很棒的答案。 tnq这么多
对我有用,应该使用这个配置: \app\config\app.php
P
Peter Mortensen

您还可以尝试在终端或命令中运行以下命令:

composer dump-auto 或 composer dump-auto -o php artisan cache:clear php artisan config:clear

以上对我有用。


M
Mike

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


R
Raham

首先通过 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


P
Peter Mortensen

在 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/


P
Peter Mortensen

使用 Form,而不是 form。大小写很重要。


P
Peter Mortensen

我已经尝试了一切,但只有这有帮助:

php artisan route:clear
php artisan cache:clear