0

我正在按照教程学习 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');
    }

}

请帮忙。

4

2 回答 2

1

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

Collective\Html\HtmlServiceProvider::class,

并添加别名:

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

并替换表单打开和关闭:

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



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

注意:
这是针对 laravel 5 的。

于 2016-02-04T15:10:12.077 回答
1

illuminate/html在 Laravel 5.0 中已弃用,并且尚未更新为与 Laravel 5.1+ 一起使用。

您需要将其替换为laravelcollective/htmlpackage

于 2016-02-04T17:57:13.940 回答