我的 laravel 版本 5.7.8 我正在尝试使用以下代码安装最后一个 Laravel Collective:
composer require "laravelcollective/html":"^5.4.0"
但是不起作用,为什么?
这是我在联系视图页面中的代码:
{!! Form::open(['url' => 'contact/submit']) !!}
<div class="form-group">
{{Form::label('name', 'Name')}}
{{Form::label('name', 'Enter your name')}}
</div>
<div class="form-group">
{{Form::label('email', 'E-Mail Address')}}
{{Form::label('email', 'example [email protected]')}}
</div>
{!! Form::close() !!}
你的代码没有问题,我假设你忘记了安装过程中的任何步骤
我将从初始阶段如何使用 laravelcollective/html 包开始
首先通过 Composer 安装此软件包。编辑项目的
composer.json
文件以需要 laravelcollective/html
"require": {
"laravelcollective/html": "*"
}
注意:这将下载最新版本的laravelcollective/html包
接下来,从终端更新 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.7.*,则 laravelcollective/html 包可能不是最新的。因此,您可以查看最新版本,即5.7.1。
参考:Packagist laravel/collectivehtml
如果这对您没有帮助,请查看 config/app.php 下的提供商 您需要将以下条目添加到您的提供者数组中
'Collective\Html\HtmlServiceProvider',
所以完整的数组看起来像
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
/*
* Package Service Providers...
*/
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
/*
* Collective Providers
*/
'Collective\Html\HtmlServiceProvider', //Your Provider here
/*
* Third Party Providers
*/
],
下一步是检查集合的别名是否在同一文件中正确设置(config/app.php)
'aliases' => [
// ...
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
// ...
],
希望这对您有帮助!
我解决了这个问题: 1-
composer require laravelcollective/html
“我在 Packagist 中找到它” 2 合 Laravel 项目
CONFIG/app.php:
'providers' => [
Collective\Html\HtmlServiceProvider::class,
],
“我在提供程序的末尾添加了一行代码,并且不触及任何其他内容” 3 合 Laravel 项目 配置/app.php:
'aliases' => [
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
],
4-on cmd 或 gitbash
composer update
“这将使用互联网资源!” 5- 在 cmd 或 git bash 中
php artisan serve
6-在网络浏览器上检查表格
如果您使用 LaravelCollection 版本 5.7 或更高版本,您唯一需要做的就是运行
composer require laravelcollective/html
你就可以开始了。
这个包已被弃用,所以你可以毫不费力地使用这个帮助器类
https://github.com/adel-ezz/laravelcollective_alternativeHelper