HtmlServiceProvider.php 第 36 行中的 FatalErrorException:laravel

Posted

技术标签:

【中文标题】HtmlServiceProvider.php 第 36 行中的 FatalErrorException:laravel【英文标题】:FatalErrorException in HtmlServiceProvider.php line 36: laravel 【发布时间】:2016-03-28 15:09:52 【问题描述】:

我正在使用 laravel 5.2,但出现以下错误 htmlServiceProvider.php 第 36 行中的 FatalErrorException: 调用未定义的方法 Illuminate\Foundation\Application::bindShared()

我的 app.php 文件是

<?php

return [


    'env' => env('APP_ENV', 'production'),


    'debug' => env('APP_DEBUG', false),


    'url' => 'http://localhost',


    'timezone' => 'UTC',


    'locale' => 'en',


    'fallback_locale' => 'en',


    'key' => env('APP_KEY'),

    'cipher' => 'AES-256-CBC',


    'log' => env('APP_LOG', 'single'),


    '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\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,
        'Illuminate\Html\HtmlServiceProvider',

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

    ],


    '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,
        '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,
        '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'      => 'Illuminate\Html\FormFacade',
        'Html'      => 'Illuminate\Html\HtmlFacade',

    ],

];

而signup_form.blade.php文件是

<h1>signupform</h1>

<div  class="signup-form">
  !! Form::open() !!

  !! Form::text('email','',array('class'=>'email','id'=>"email","placeholder"=>'Email address'))!!

    !! Form::close() !!

</div>

还有我的 routes.php 文件

<?php



Route::get('/', function () 
    return view('welcome');
);
Route::get('home', function () 
    echo 'welome home';
);

Route::get('signup', 'Auth\HomeController@signupform');

每当我在浏览器中打开表单时,它都会显示上述错误。

【问题讨论】:

app.php中尝试用Illuminate\Html\HtmlServiceProvider::class替换'Illuminate\Html\HtmlServiceProvider' @Moppo 我改变了它,但它仍然给出同样的错误 【参考方案1】:

这是LaravelCollective.com的教程。

【讨论】:

【参考方案2】:

这个技巧对我有用 在 vendor\illuminate\html\HtmlServiceProvider.php 文件中将所有“bindShared”函数的名称改为“singleton”

例如: 改变

$this->app->bindShared('html', function($app)

   return new HtmlBuilder($app['url']);
);

进入

$this->app->singleton('html', function($app)

   return new HtmlBuilder($app['url']);
);

【讨论】:

【参考方案3】:

首先,在composer.json文件中需要替换:

"illuminate/html": "^5.0"

"laravelcollective/html":"5.2.*"

接下来,您需要通过在终端中键入以下命令从终端更新作曲家:composer update

接下来,在config/app.php 文件中,替换:

'Illuminate\Html\HtmlServiceProvider::class'`

'Collective\Html\HtmlServiceProvider::class'

接下来你替换这两个类的别名:

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

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

最后,您需要更新您的 routes.php 文件,将“web”中间件替换为:

Route::group(['middleware' => ['web']], function () use ($router) 
    $router->resource('blogs', 'BlogsController');
);

【讨论】:

这对我有用。纠正了一个错字(':class' 而不是 '::class)!【参考方案4】:

对我有用的“技巧”是上面提到的,因为 Illuminate/HTML 包已被弃用:

使用:laravelcollective/html https://***.com/a/34991188/3327198

在终端(CLI)中:composer 需要 laravelcollective/html

在 config/app.php 中添加这一行 在提供商组中:

Collective\Html\HtmlServiceProvider::class,

在别名组中: 'Form' => Collective\Html\FormFacade::class, 'Html' => 集体\Html\HtmlFacade::class,

【讨论】:

【参考方案5】:

你需要删除:

'Illuminate\Html\HtmlServiceProvider',

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

形成你的`config/app.php

然后从您的composer.json 中删除illuminate/html 然后添加到您的composer.json

"laravelcollective/html": "5.*"

require 部分

然后运行composer install

您还需要按照https://laravelcollective.com/docs/5.1/html#installation 的说明完成此软件包安装

编辑它现在可能无法正常工作,因为:https://github.com/LaravelCollective/html/issues/133 - 合并此 PR 后可能会解决:https://github.com/illuminate/html/pull/31/files

【讨论】:

谢谢!非常有帮助。 :-)

以上是关于HtmlServiceProvider.php 第 36 行中的 FatalErrorException:laravel的主要内容,如果未能解决你的问题,请参考以下文章

c# listView1写入第一行第一列

计算机图形学 Peter Shirley

第0课 - 数据结构引言

《Pandas Cookbook》第02章 DataFrame基本操作

第一篇 用于测试使用

mysql 怎么计算第二个数字和第一个数字差值