Laravelcollective/html not working in Laravel 5.5

时光总嘲笑我的痴心妄想 提交于 2020-01-01 12:12:09

问题


I've tried to use the Laravelcollective/html on laravel 5.5 by loading the v5.4 in my composer.json file but that didn't work. This is the code in the composer.json file:

"laravelcollective/html":"^5.4.0",

and loading it into my app configuration file app.php: inside the providers array

Collective\Html\HtmlServiceProvider::class,

But after i used the blade code to create the form it didn't work, here's the blade code.

{!! Form::open(['route' => 'posts.store']) !!}

{{Form::label('title','Title:')}}

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

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

回答1:


In composer.json, add:

"require": {
    // ...,
     "laravelcollective/html": "^5.4.0"
    // ...,
 },

In app/config/app.php, add the following to each array:

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

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

And in your blade file:

{!! Form::open(['route' => 'posts.store']) !!}
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', null, array('class' => 'form-control')) !!}
{!! Form::close() !!}

Then run $ composer require laravelcollective/html:^5.4.0 after adding the above. :)




回答2:


You can use this command

composer require --update-with-all-dependencies "laravelcollective/html 5.6.*"... since you are using laravel 5.5 the command to use will be 
composer require "laravelcollective/html 5.5.*"



回答3:


You also have to add the following to your alias array:

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

],




回答4:


The syntax you are using is old style.

{{Form::label('title','Title:')}} 

It needs to be

{!! Form::label('title','Title:') !!}



回答5:


You can do it in laravel 5.5 too. Step 1: Install from Command: composer require "laravelcollective/html":"^5.5"

Step 2: After install you have to add providers and aliases in config/app.php file, so let' follow bellow file how to add.

Step 2.1:

<?php

'providers' => [

    // ...

    Collective\Html\HtmlServiceProvider::class,

    // ...

  ],

'aliases' => [

    // ...

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

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

    // ...

  ],

Step 3: After added above providers, you have to check on your project.

Step 4: Done.

Thanks.




回答6:


it Simple use this one:

composer require laravelcollective/html


来源:https://stackoverflow.com/questions/46392542/laravelcollective-html-not-working-in-laravel-5-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!