php 未找到 Laravel 5 类“表单”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28753767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:02:48  来源:igfitidea点击:

Laravel 5 Class 'form' not found

phplaravelcomposer-php

提问by Dan Hastings

I have added "illuminate/html": "5.*" to composer.json and ran "composer update".

我已将 "illuminate/html": "5.*" 添加到 composer.json 并运行 "composer update"。

  - Installing illuminate/html (v5.0.0)
    Loading from cache

I ran this command in the root of the website. I modified the composer.json file in /root/.composer... and in the root of the project and neither have made a difference.

我在网站的根目录中运行了这个命令。我修改了 /root/.composer... 和项目根目录中的 composer.json 文件,两者都没有产生任何影响。

This downloaded the class and it seemed to install. I have added the following to file config/app.php.

这下载了课程,它似乎安装了。我已将以下内容添加到文件config/app.php 中

    'Illuminate\Html\HtmlServiceProvider',

    'Form'      => 'Illuminate\Html\FormFacade',
    'Html'      => 'Illuminate\Html\HtmlFacade',

I think I have an idea what is wrong, but I don't know how to fix it. My install is in '/var/www/website'. I have checked the file path and the Htmlfolder does not exist.

我想我知道出了什么问题,但我不知道如何解决。我的安装在“/var/www/website”中。我检查了文件路径,Html文件夹不存在。

"/var/www/website/vendor/laravel/framework/src/Illuminate/Html"

I was able to find the class files, but in a different directory.

我能够找到类文件,但在不同的目录中。

"/var/www/website/vendor/illuminate/html"

I manually copied the files over to the main Laravel illuminate/htmlfolder, but this hasn't worked either.

我手动将文件复制到 Laravel 主 Laravel照明/html文件夹,但这也没有奏效。

采纳答案by mhanson01

This may not be the answer you're looking for, but I'd recommend using the now community maintained repository Laravel Collective Forms & HTMLas the main repositories have been deprecated.

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

Laravel Collective is in the process of updating their website. You may view the documentation on GitHubif needed.

Laravel Collective 正在更新他们的网站。如果需要,您可以查看 GitHub 上的文档

回答by CONvid19

Formisn't included in laravel5.0as it was on 4.0, steps to include it:

Form未包含在laravel5.0 中,因为它在4.0 中,包含它的步骤:

Begin by installing laravelcollective/htmlpackage through Composer. Edit your project's composer.jsonfile to require:

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

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

Next, update composerfrom the Terminal:

接下来,composer从终端更新:

composer update


Next, add your new provider to the providersarray of config/app.php:

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

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


Finally, add two class aliases to the aliasesarray of config/app.php:

最后,将两个类别名添加到 的aliases数组中config/app.php

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


At this point, Formshould be working

在这一点上,Form应该工作

Source

来源



UpdateLaravel 5.8(2019-04-05):

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

In Laravel 5.8, the providersin the config/app.phpcan be declared as:

Laravel 5.8中,providersconfig/app.php可以声明为:

Collective\Html\HtmlServiceProvider::class,

instead of:

代替:

'Collective\Html\HtmlServiceProvider',

This notation is the same for the aliases.

对于别名,这种表示法是相同的。

回答by user28864

You can also try running the following commands in Terminal or Command:

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

  1. composer dump-autoor composer dump-auto -o
  2. php artisan cache:clear
  3. php artisan config:clear
  1. composer dump-auto或者 composer dump-auto -o
  2. php artisan cache:clear
  3. php artisan config:clear

The above worked for me.

以上对我有用。

回答by Ahmed Mahmoud

Just type the following command in terminal at the project directory and installation is done according the Laravel version:

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

composer require "laravelcollective/html"

Then add these lines in config/app.php

然后将这些行添加到 config/app.php

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

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

回答by jessier3

There is an update to this for Laravel 5.2. Notice this is a slightly different format from what is indicated above.

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

Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/html.

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

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

Next, update Composer from the Terminal:

接下来,从终端更新 Composer:

composer update

Next, add your new provider to the providers array of config/app.php:

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

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

Finally, add two class aliases to the aliases array of config/app.php:

最后,在 config/app.php 的 aliases 数组中添加两个类别名:

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

After making this update this code worked for me on a new installation of Laravel 5.2:

进行此更新后,此代码在新安装的 Laravel 5.2 上对我有用:

{!! Form::open(array('url' => 'foo/bar')) !!}
    //
{!! Form::close() !!}

I got this information here: https://laravelcollective.com/docs/5.2/html

我在这里得到了这个信息:https: //laravelcollective.com/docs/5.2/html

回答by Raham

Begin by installing this package through Composer. Run the following from the terminal:

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

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

Next, add your new provider to the providers array of config/app.php:

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

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

Finally, add two class aliases to the aliases array of config/app.php:

最后,在 config/app.php 的 aliases 数组中添加两个类别名:

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

SRC:

资源中心:

https://laravelcollective.com/docs/5.3/html

https://laravelcollective.com/docs/5.3/html

回答by Maniruzzaman Akash

In Laravel Version - 4, HTML and Form existed, but not now.

在 Laravel Version - 4 中,HTML 和 Form 存在,但现在不存在。

Why:

为什么:

The only reason is they have collected some user requirements and they want it more lightweight and so they removed it as in the sense that a user can add it manually.

唯一的原因是他们收集了一些用户需求,他们希望它更轻量级,因此他们将其删除,因为用户可以手动添加它。

What to do to add HTML & Forms in Laravel 5.2 or 5.3:

如何在 Laravel 5.2 或 5.3 中添加 HTML 和表单:

For 5.2:

对于 5.2:

Go to the Laravel Collective siteand installation processes have demonstrated their.

转到Laravel Collective 站点和安装过程已经展示了它们。

Like for 5.2: on the command line, run the command

像 5.2:在命令行上,运行命令

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

Then, in the providerarray which is in config/app.php. Add this line at last using a comma(,):

然后,在config/app.php中的provider数组。最后使用逗号(,)添加这一行:

Collective\Html\HtmlServiceProvider::class,

For using HTML and FORM text we need to alias them in the aliases arrayof config/app.php. Add the two lines at the last

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

'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

And for 5.3:

对于 5.3:

Just run the command

只需运行命令

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

And the rest of the procedure is like 5.2.

其余的程序就像5.2

Then you can use Laravel Form and other HTML links in your projects. For this, follow this documentation:

然后你可以在你的项目中使用 Laravel Form 和其他 HTML 链接。为此,请遵循以下文档:

5.2:https://laravelcollective.com/docs/5.2/html

5.2:https : //laravelcollective.com/docs/5.2/html

5.3:https://laravelcollective.com/docs/5.3/html

5.3:https : //laravelcollective.com/docs/5.3/html

Demo Code:

演示代码:

To open a form, open and close a tag:

要打开一个表单,打开和关闭一个标签:

{!! Form::open(['url' => 'foo/bar']) !!}

{!! Form::close() !!}

And for creating label and input text with a Bootstrap form-control class and other use:

以及使用 Bootstrap 表单控件类和其他用途创建标签和输入文本:

{!! Form::label('title', 'Post Title') !!}
{!! Form::text('title', null, array('class' => 'form-control')) !!}

And for more, use the documentation, https://laravelcollective.com/.

如需更多信息,请使用文档https://laravelcollective.com/

回答by kpp

Use Form, not form. The capitalization counts.

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

回答by Krzysztof Dziuba

I have tried everything, but only this helped:

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

php artisan route:clear
php artisan cache:clear