FatalErrorException in HtmlServiceProvider.php line 36: laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34414389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:51:55  来源:igfitidea点击:

FatalErrorException in HtmlServiceProvider.php line 36: laravel

laravellaravel-routinglaravel-5.2

提问by Murali Krishna

I am using laravel 5.2 and I am getting following error FatalErrorException in HtmlServiceProvider.php line 36: Call to undefined method Illuminate\Foundation\Application::bindShared()

I am using laravel 5.2 and I am getting following error FatalErrorException in HtmlServiceProvider.php line 36: Call to undefined method Illuminate\Foundation\Application::bindShared()

my app.php file is

my app.php file is

<?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',

    ],

];

And signup_form.blade.php file is

And signup_form.blade.php file is

<h1>signupform</h1>

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

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

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

</div>

And my routes.php file

And my routes.php file

<?php



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

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

whenever i open the form in browser it shows the above error.

whenever i open the form in browser it shows the above error.

回答by Marcin Nabia?ek

You need to remove:

You need to remove:

'Illuminate\Html\HtmlServiceProvider',

and

and

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

form your `config/app.php

form your `config/app.php

then remove from your composer.jsonilluminate/htmlthen add to your composer.json:

then remove from your composer.jsonilluminate/htmlthen add to your composer.json:

"laravelcollective/html": "5.*"

in requiresection

in requiresection

then run composer install

then run composer install

And further you need to follow instructions for https://laravelcollective.com/docs/5.1/html#installationto complete this package installation

And further you need to follow instructions for https://laravelcollective.com/docs/5.1/html#installationto complete this package installation

EDITIT might be not working at this moment because of this: https://github.com/LaravelCollective/html/issues/133- it will be probably solved after merging this PR: https://github.com/illuminate/html/pull/31/files

EDITIT might be not working at this moment because of this: https://github.com/LaravelCollective/html/issues/133- it will be probably solved after merging this PR: https://github.com/illuminate/html/pull/31/files

回答by favourworks

First, in the composer.jsonfile need to replace:

First, in the composer.jsonfile need to replace:

"illuminate/html": "^5.0"

with

with

"laravelcollective/html":"5.2.*"

Next you need update the composer from the terminal by typing this command in your terminal: composer update.

Next you need update the composer from the terminal by typing this command in your terminal: composer update.

Next, in the config/app.phpfile, you replace the:

Next, in the config/app.phpfile, you replace the:

'Illuminate\Html\HtmlServiceProvider::class'`

with

with

'Collective\Html\HtmlServiceProvider::class'

Next you replace these two classes aliases:

Next you replace these two classes aliases:

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

with

with

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

Lastly, you need to update your routes.php file by replacing the 'web' middleware with:

Lastly, you need to update your routes.php file by replacing the 'web' middleware with:

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

回答by Abduhafiz

Here's a tutorial on LaravelCollective.com.

Here's a tutorial on LaravelCollective.com.

回答by Andrei-Cosmin Pavel

The "trick" that worked for me is the one mentioned above because Illuminate/HTML package has been deprecated:

The "trick" that worked for me is the one mentioned above because Illuminate/HTML package has been deprecated:

Use:laravelcollective/html https://stackoverflow.com/a/34991188/3327198

Use:laravelcollective/html https://stackoverflow.com/a/34991188/3327198

In the terminal (CLI): composer require laravelcollective/html

In the terminal (CLI): composer require laravelcollective/html

Add this lines in config/app.php IN PROVIDERS GROUP:

Add this lines in config/app.php IN PROVIDERS GROUP:

Collective\Html\HtmlServiceProvider::class,

Collective\Html\HtmlServiceProvider::class,

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

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

回答by user3723572

This trick worked for me Change the name of all "bindShared" functions into "singleton" in the vendor\illuminate\html\HtmlServiceProvider.php file

This trick worked for me Change the name of all "bindShared" functions into "singleton" in the vendor\illuminate\html\HtmlServiceProvider.php file

For example: Change

For example: Change

$this->app->bindShared('html', function($app)
{
   return new HtmlBuilder($app['url']);
});
$this->app->bindShared('html', function($app)
{
   return new HtmlBuilder($app['url']);
});

into

into

$this->app->singleton('html', function($app)
{
   return new HtmlBuilder($app['url']);
});
$this->app->singleton('html', function($app)
{
   return new HtmlBuilder($app['url']);
});