【问题标题】:Laravel 5 Class 'form' not found未找到 Laravel 5 类“表单”
【发布时间】:2015-04-29 11:57:00
【问题描述】:

我已将 "illuminate/html": "5.*" 添加到 composer.json 并运行 "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 主文件夹,但这也不起作用。

【问题讨论】:

    标签: php laravel composer-php


    【解决方案1】:

    Form 不包含在 laravel 5.0 中,因为它在 4.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 文档中没有明确说明默认情况下不包含相当基本的组件。
    【解决方案2】:

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

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

    【讨论】:

    • 知道为什么它在 v5 中被删除了吗?
    • 似乎他们想让它更轻量级,让人们只在需要时添加东西。
    • 他们在升级指南或其他地方注意到了吗?没看到。
    • 谢谢 不知道 laravel 的新内容,它仍然在主要文档中,所以我不知道这不在 v5 中。
    【解决方案3】:

    只需在项目目录下的终端输入以下命令,即可按照 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
    【解决方案4】:

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

    1. composer dump-autocomposer dump-auto -o
    2. php artisan cache:clear
    3. php artisan config:clear

    以上对我有用。

    【讨论】:

      【解决方案5】:

      Laravel 5.2 对此进行了更新。请注意,这与上述格式略有不同。

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

      "require": {
          "laravelcollective/html": "5.2.*"
      }
      

      接下来,从终端更新 Composer:

      composer update
      

      接下来,将你的新提供者添加到 config/app.php 的 providers 数组中:

        '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

      【讨论】:

        【解决方案6】:

        首先通过 Composer 安装这个包。从终端运行以下命令:

        composer require "laravelcollective/html":"^5.3.0"
        

        接下来,将你的新提供者添加到 config/app.php 的 providers 数组中:

        '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

        【讨论】:

          【解决方案7】:

          在 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 中的 provider 数组中。最后用逗号(,)添加这一行:

          Collective\Html\HtmlServiceProvider::class,
          

          为了使用 HTML 和 FORM 文本,我们需要在 config/app.phpaliases 数组 中为它们设置别名。在最后添加两行

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

          【讨论】:

            【解决方案8】:

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

            【讨论】:

              【解决方案9】:

              我已经尝试了所有方法,但只有这个有帮助:

              php artisan route:clear
              php artisan cache:clear
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2015-07-07
                • 2015-05-05
                • 1970-01-01
                • 2016-07-12
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2015-04-16
                相关资源
                最近更新 更多