【问题标题】:Laravel 5.4 Class 'form' not found未找到 Laravel 5.4 类“表单”
【发布时间】:2017-04-04 12:35:29
【问题描述】:

我遇到了问题'Class 'form' not found'我目前使用的是 laravel 5.4。我已经尽力解决了。

谢谢

错误是:糟糕,好像出了点问题。

1/1

d0b19e04e5a1f8a5507d8ca427362b23807103ca.php 第 23 行中的 FatalErrorException: 找不到类“表格” 在 d0b19e04e5a1f8a5507d8ca427362b23807103ca.php 第 23 行

这是我的补偿

{
    "require": {
       "php": ">=5.6.4",
       "laravel/framework": "5.4.*",
       "laravel/tinker": "~1.0",
       "laravelcollective/html": "^5.4"
    }, 
}

我运行 composer update 命令。

这是我的 app.php

'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\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    'Collective\Html\HtmlServiceProvider',


    /*
     * Package Service Providers...
     */
    Laravel\Tinker\TinkerServiceProvider::class,

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

],

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/

'aliases' => [

    'App' => Illuminate\Support\Facades\App::class,
    'Artisan' => Illuminate\Support\Facades\Artisan::class,
    'Auth' => Illuminate\Support\Facades\Auth::class,
    'Blade' => Illuminate\Support\Facades\Blade::class,
    'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
    'Bus' => Illuminate\Support\Facades\Bus::class,
    'Cache' => Illuminate\Support\Facades\Cache::class,
    'Config' => Illuminate\Support\Facades\Config::class,
    'Cookie' => Illuminate\Support\Facades\Cookie::class,
    'Crypt' => Illuminate\Support\Facades\Crypt::class,
    'DB' => Illuminate\Support\Facades\DB::class,
    'Eloquent' => Illuminate\Database\Eloquent\Model::class,
    'Event' => Illuminate\Support\Facades\Event::class,
    'File' => Illuminate\Support\Facades\File::class,
    'Gate' => Illuminate\Support\Facades\Gate::class,
    'Hash' => Illuminate\Support\Facades\Hash::class,
    'Lang' => Illuminate\Support\Facades\Lang::class,
    'Log' => Illuminate\Support\Facades\Log::class,
    'Mail' => Illuminate\Support\Facades\Mail::class,
    'Notification' => Illuminate\Support\Facades\Notification::class,
    'Password' => Illuminate\Support\Facades\Password::class,
    'Queue' => Illuminate\Support\Facades\Queue::class,
    'Redirect' => Illuminate\Support\Facades\Redirect::class,
    'Redis' => Illuminate\Support\Facades\Redis::class,
    'Request' => Illuminate\Support\Facades\Request::class,
    'Response' => Illuminate\Support\Facades\Response::class,
    'Route' => Illuminate\Support\Facades\Route::class,
    'Schema' => Illuminate\Support\Facades\Schema::class,
    'Session' => Illuminate\Support\Facades\Session::class,
    'Storage' => Illuminate\Support\Facades\Storage::class,
    'URL' => Illuminate\Support\Facades\URL::class,
    'Validator' => Illuminate\Support\Facades\Validator::class,
    'View'      => Illuminate\Support\Facades\View::class,
    'FORM' => 'Collective\Html\FormFacade',
    'HTML' => 'Collective\Html\HtmlFacade',
],

];

在formupload.blade.php中使用表单

@if(isset($success))
    <div class="alert alert-success"> {{$success}} </div>
@endif
    {!! Form::open(['action'=>'ImageController@store', 'files'=>true]) !!}

    <div class="form-group">
        {!! Form::label('title', 'Title:') !!}
        {!! Form::text('title', null, ['class'=>'form-control']) !!}
    </div>

    <div class="form-group">
        {!! Form::label('description', 'Description:') !!}
        {!! Form::textarea('description', null, ['class'=>'form-control', 'rows'=>5] ) !!}
    </div>

    <div class="form-group">
        {!! Form::label('image', 'Choose an image') !!}
        {!! Form::file('image') !!}
    </div>

    <div class="form-group">
        {!! Form::submit('Save', array( 'class'=>'btn btn-danger form-control' )) !!}
    </div>

    {!! Form::close() !!}
    <div class="alert-warning">
        @foreach( $errors->all() as $error )
           <br> {{ $error }}
        @endforeach
    </div>

</div>

【问题讨论】:

  • 请展示这些“最大努力”,首先展示一些代码和预期结果
  • 看看这个link
  • R. Manzarei 先生您好,此链接仅适用于 5.3 版本我目前使用的是 5.4.17 版本的 laravel
  • 嗨@Shogunivar我已经添加了“require”:{“laravelcollective/html”:“^5.4”},添加到composer.json并添加了'providers'=> [''Collective\Html\HtmlServiceProvider ',] & 添加到别名 'FORM' => 'Collective\Html\FormFacade', 'HTML' => 'Collective\Html\HtmlFacade',在 app.php 中也可以在 cmd 中运行 composer update 命令

标签: forms laravel


【解决方案1】:

把它放在composer.json中

"require": {
        "laravelcollective/html": "^5.4"
 },

然后运行

composer update 

事后指挥

或者

composer require laravelcollective/html

然后将其添加到您的 config/app.php 的 providers 部分数组中

Collective\Html\HtmlServiceProvider::class,

然后在别名数组的config/app.php中添加两个类别名

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

【讨论】:

    【解决方案2】:

    看起来您在 app.php 中将表单类的别名设置为“FORM”:

    'FORM' =&gt; 'Collective\Html\FormFacade',

    尝试将其更改为 Form,如下所示:

    'Form' =&gt; 'Collective\Html\FormFacade',

    那么它应该可以工作

    【讨论】:

    • 嗨@Shogunivar 感谢您给我正确的答案。是的,它工作正常。它的正确答案。再次感谢您的大力帮助。
    【解决方案3】:

    运行命令

     composer require laravelcollective/html
    

    当作曲家更新 require html laravel 集合时 然后将这两行添加到 config/app.php 的
    'aliases' => [ ],

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

    然后将该行添加到 config/app.php
    'providers' => [ ], 并保存文件

    Collective\Html\HtmlServiceProvider::class,
    

    【讨论】:

      【解决方案4】:

      运行命令

      composer require laravelcollective/html
      

      将这两行添加到 config/app.php 的部分 'aliases' =&gt; [ ],

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

      将该行添加到 config/app.php 'providers' =&gt; [ ],然后保存文件

      Collective\Html\HtmlServiceProvider::class,
      

      这也适用于 6.X

      【讨论】:

        【解决方案5】:

        config/app.php 中的类别名

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

        这对我有用

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-03-15
          • 2021-04-07
          • 1970-01-01
          • 1970-01-01
          • 2015-04-29
          • 2016-07-12
          • 1970-01-01
          相关资源
          最近更新 更多