方法打开不存在,Laravel,Form facade

时间:2016-02-04 10:34:28

标签: laravel laravel-5 laravel-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');
    }

}

请帮助。

2 个答案:

答案 0 :(得分:1)

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

Collective\Html\HtmlServiceProvider::class,

并添加别名:

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

并替换表单打开和关闭:

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



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

注释:
这是为了laravel 5.

答案 1 :(得分:1)

illuminate/html已弃用Laravel 5.0,尚未更新以与Laravel 5.1 +配合使用。

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