TwigBridge: Getting `Unresolvable dependency` exception

I’m using https://github.com/barryvdh/laravel-ide-helper to generate auto-complete for PhpStorm. I guess it’s invoking all services providers to work. As a result I’m getting following exception:

Exception: Cannot instantiate Twig extension 'TwigBridge\Extension\Laravel\Form': Unresolvable dependency resolving [Parameter #2 [ <required> $csrfToken ]] in class Illuminate\Html\FormBuilder
Skipping \TwigBridge\Facade\Twig.
A new helper file was written to _ide_helper.php

I guess this happens because the mentioned TwigBridge\Extension\Laravel\Form class has dependency on FormBuilder (see https://github.com/rcrowe/TwigBridge/blob/master/src/Extension/Laravel/Form.php#L34), which happens to have 3rd required argument called $csrfToken: https://github.com/laravel/framework/blob/4.2/src/Illuminate/Html/FormBuilder.php#L82

Used Laravel Version: 4.3

Related issue: barryvdh/laravel-ide-helper#119

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Comments: 46 (25 by maintainers)

Commits related to this issue

Most upvoted comments

@enchance the fix was to add a app/Providers/FormServiceProvider.php with the following content:

<?php namespace AppNamespace\Providers;

use Collective\Html\FormBuilder;
use Illuminate\Support\ServiceProvider;

/**
 * Class FormServiceProvider
 *
 * Fix for https://github.com/rcrowe/TwigBridge/issues/150
 *
 * @package AppNamespace\Providers
 */
class FormServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bindIf('Collective\Html\FormBuilder', function () {
            return new FormBuilder(
                $this->app->make('Collective\Html\HtmlBuilder'),
                $this->app->make('Illuminate\Routing\UrlGenerator'),
                csrf_token()
            );
        });
    }
}