search
HomeBackend DevelopmentPHP Tutoriallaravel 5.2 form模块调用时出错

错误代码

 Call to undefined method Illuminate\Foundation\Application::bindShared()

原因

The Form and HTML helpers have been deprecated in Laravel 5.0; form模块依赖于laravel 5.0框架,所以在默认的5.2框架里调用还是会有问题,现时5.2还没有作出修复,所以需要重新安装。

解决

1.在composer.json文件的require里添加一行”laravelcollective/html”: “~5.0″完成版

    "require": {        "php": ">=5.5.9",        "laravel/framework": "5.2.*",        "illuminate/html": "^5.0",        "barryvdh/laravel-ide-helper": "v2.1.2",        "laravelcollective/html": "~5.0"    },

composer.json位置在laravel目录根层

2.然后运行命令

composer update

主要是通过composer来重新管理laravel框架的文件

以下是更新过程

composer update> php artisan clear-compiledLoading composer repositories with package informationUpdating dependencies (including require-dev)  - Removing symfony/yaml (v3.0.1)  - Installing symfony/yaml (v3.0.2)    Downloading: 100%  - Removing phpspec/prophecy (v1.5.0)  - Installing phpspec/prophecy (v1.6.0)    Downloading: 100%  - Removing phpunit/phpunit (4.8.21)  - Installing phpunit/phpunit (4.8.23)    Downloading: 100%  - Removing symfony/css-selector (v3.0.1)  - Installing symfony/css-selector (v3.0.2)    Downloading: 100%  - Removing symfony/dom-crawler (v3.0.1)  - Installing symfony/dom-crawler (v3.0.2)    Downloading: 100%  - Removing paragonie/random_compat (1.1.6)  - Installing paragonie/random_compat (v1.2.0)    Downloading: 100%  - Removing symfony/console (v3.0.1)  - Installing symfony/console (v3.0.2)    Downloading: 100%  - Removing symfony/finder (v3.0.1)  - Installing symfony/finder (v3.0.2)    Downloading: 100%  - Removing symfony/debug (v3.0.1)  - Installing symfony/debug (v3.0.2)    Downloading: 100%  - Removing symfony/http-foundation (v3.0.1)  - Installing symfony/http-foundation (v3.0.2)    Downloading: 100%  - Removing symfony/event-dispatcher (v3.0.1)  - Installing symfony/event-dispatcher (v3.0.2)    Downloading: 100%  - Removing symfony/http-kernel (v3.0.1)  - Installing symfony/http-kernel (v3.0.2)    Downloading: 100%  - Removing symfony/process (v3.0.1)  - Installing symfony/process (v3.0.2)    Downloading: 100%  - Updating symfony/routing (v3.0.1 => v3.0.2)    The package has modified files:    M .gitignore    M Annotation/Route.php    M CHANGELOG.md    M CompiledRoute.php    M Exception/ExceptionInterface.php    M Exception/InvalidParameterException.php    M Exception/MethodNotAllowedException.php    M Exception/MissingMandatoryParametersException.php    M Exception/ResourceNotFoundException.php    M Exception/RouteNotFoundException.php-10 more files modified, choose "v" to view the full list    Discard changes [y,n,v,d,s,?]? y    Checking out 4686baa55a835e1c1ede9b86ba02415c8c8d6166  - Removing symfony/translation (v3.0.1)  - Installing symfony/translation (v3.0.2)    Downloading: 100%  - Removing symfony/var-dumper (v3.0.1)  - Installing symfony/var-dumper (v3.0.2)    Downloading: 100%  - Removing laravel/framework (v5.2.12)  - Installing laravel/framework (v5.2.16)    Downloading: 100%  - Installing laravelcollective/html (v5.2.4)    Downloading: 100%Writing lock fileGenerating autoload files> php artisan optimizeGenerating optimized class loader

3.更新成功后,修改config/app.php文件增加配置:

#增加providers数组项  'providers' => [    // ...    Collective\Html\HtmlServiceProvider::class,    // ...  ], #增加alias数组项   'aliases' => [    // ...      'Form' => Collective\Html\FormFacade::class,      'Html' => Collective\Html\HtmlFacade::class,    // ...  ],

以下是完成版

  '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,        Collective\Html\HtmlServiceProvider::class, #注意,就是这里        'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', // Laravel IDE helper        /*         * Application Service Providers...         */        App\Providers\AppServiceProvider::class,        App\Providers\AuthServiceProvider::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,        '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'      => Collective\Html\FormFacade::class,#注意,就是这里        'Html'      => Collective\Html\HtmlFacade::class,#注意,就是这里    ],

参考文件:

https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0

https://laravelcollective.com/docs/5.1/html#installation

http://stackoverflow.com/questions/34414389/fatalerrorexception-in-htmlserviceprovider-php-line-36-laravel

本文由 PeterYuan 创作,采用 署名-非商业性使用 2.5 中国大陆 进行许可。 转载、引用前需联系作者,并署名作者且注明文章出处。神一样的少年 » laravel 5.2 form模块调用时出错

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Discover File Downloads in Laravel with Storage::downloadDiscover File Downloads in Laravel with Storage::downloadMar 06, 2025 am 02:22 AM

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

How to Register and Use Laravel Service ProvidersHow to Register and Use Laravel Service ProvidersMar 07, 2025 am 01:18 AM

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment