方法 open 不存在,Laravel,Form facade

Method open does not exist, Laravel, Form facade

我正在按照教程学习 laravel。我被这个错误困住了

ErrorException in Macroable.php line 81: Method open does not exist. (View: path\to\project\resources\views\form.blade.php)

我正在使用 FormFacade。早些时候我遇到一个错误说: Call to undefined method Illuminate\Foundation\Application::bindShared()

我通过在整个文件

中将 bindShared 替换为 singleton 克服了这个问题

/path/project/vendor/illuminate/html/HtmlServiceProvider.php

form.blade.php

<html>


    <head>
        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    </head>

    <body>
        <h1>Create a new form</h1>
        <hr/>

        {{ Form::open() }}



        {{ Form::close() }}
    </body>


</html>

HtmlServiceProvider.php

use Illuminate\Support\ServiceProvider;

class HtmlServiceProvider extends ServiceProvider {

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->registerHtmlBuilder();

        $this->registerFormBuilder();

        $this->app->alias('html', 'Illuminate\Html\HtmlBuilder');
        $this->app->alias('form', 'Illuminate\Html\FormBuilder');
    }

    /**
     * Register the HTML builder instance.
     *
     * @return void
     */
    protected function registerHtmlBuilder()
    {
        $this->app->singleton('html', function($app)
        {
            return new HtmlBuilder($app['url']);
        });
    }

    /**
     * Register the form builder instance.
     *
     * @return void
     */
    protected function registerFormBuilder()
    {
        $this->app->singleton('form', function($app)
        {
            $form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());

            return $form->setSessionStore($app['session.store']);
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return array('html', 'form');
    }

}

请帮忙。

添加您的 config/app.php 供应商:

Collective\Html\HtmlServiceProvider::class,

并添加别名:

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

并替换表格的打开和关闭:

    {!! Form::open() !!}



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

备注:
这是为了 laravel 5。

illuminate/html 已因 Laravel 5.0 而弃用,并且尚未更新以与 Laravel 5.1+ 一起使用。

您需要将其替换为 laravelcollective/html package