【问题标题】:Installing laravel collective doesn't work?安装 laravel 集体不起作用?
【发布时间】:2018-10-09 04:48:11
【问题描述】:

我的 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 yourgmail@gmail.com')}}    
</div>
{!! Form::close() !!}

【问题讨论】:

  • "但是为什么不起作用?" - 你能解释一下什么不起作用吗?确切的错误或行为是什么?
  • 欢迎来到 Stack Overflow!其他用户将您的问题标记为低质量和需要改进。我重新措辞/格式化您的输入,使其更容易阅读/理解。请查看我的更改以确保它们反映您的意图。但我认为你的问题仍然无法回答。 现在应该edit你的问题,添加缺失的细节(见minimal reproducible example)。如果您对我有其他问题或反馈,请随时给我留言。
  • 嗨,marcin 先生,当我在下图中为用户名和密码创建输入框时,代码视图作为文本没有添加输入的地方。请检查这个prnt.sc/l44kmz

标签: laravel forms


【解决方案1】:

您的代码没有问题,我假设您在安装过程中忘记了任何步骤

我会从初始阶段如何使用 laravelcollective/html 包开始


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

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

注意:这将下载最新版本的laravelcollective/html

接下来,从终端更新 Composer:

composer update

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

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

config/app.php:aliases数组中添加两个类别名

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

现在把你的代码放到视图文件中,在浏览器中检查就不会出错了

【讨论】:

    【解决方案2】:

    如果您在最新版本(5.7.*)中运行 Laravel,则 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',
    // ...
    ],
    

    希望对您有所帮助!

    【讨论】:

    • 谢谢你为我编辑它!找不到最新信息,因为他们的网站只显示到 5.4,我想知道他们为什么不再更新他们的网站...
    【解决方案3】:

    我解决了这个问题: 1-

      composer require laravelcollective/html
    

    “我在 packagegist 中找到了” 2-IN LARAVEL 项目

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

    “我在提供程序的末尾添加了一行代码,并且不涉及其他任何内容” 3-IN 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- 在网络浏览器上查看表单

    【讨论】:

      【解决方案4】:

      如果你使用 LaravelCollection 5.7 或更新版本,你唯一需要做的就是运行

      composer require laravelcollective/html
      

      你可以走了。

      【讨论】:

        猜你喜欢
        • 2018-05-15
        • 1970-01-01
        • 2020-07-22
        • 1970-01-01
        • 2015-04-06
        • 2016-01-23
        • 2017-05-22
        • 2023-03-08
        • 2016-08-25
        相关资源
        最近更新 更多