RobinRadic / blade-extensions

Laravel Blade extensions like $loop->odd/$loop->index in foreach, view blocks and partials, etc
http://robin.radic.nl/blade-extensions
MIT License
267 stars 35 forks source link

app("blade-extensions.helpers")->get('minifier')->open('html') is null #72

Closed maimai-swap closed 6 years ago

maimai-swap commented 6 years ago

I got Error Message below.

ErrorException (E_ERROR)
Call to a member function open() on null (View: /home/vagrant/myapp/resources/views/mypath/myview.blade.php)

This error does not occurs at first access . But next time this error occurs. Is this because of this code on view cache file? <?php echo app("blade-extensions.helpers")->get('minifier')->open('html'); ?>

I confirmed like this. <?php dd( app("blade-extensions.helpers"))?>

HelperRepository {#416 ▼
  #helpers: []
}

I use this

"name": "radic/blade-extensions",
            "version": "7.0.2",
            "source": {
                "type": "git",
                "url": "https://github.com/RobinRadic/blade-extensions.git",
                "reference": "2ddc36e99e9e462e67ba90a8d889ced651426d88"
            },

I resolved this error that I write my application class extend Radic\BladeExtensions\BladeExtensionsServiceProvider

    protected function registerHelperRepository()
    {
        $this->app->singleton('blade-extensions.helpers', function ($app) {
            $helpers = new HelperRepository();
            $helpers->put('minifier', $app->build(Helpers\Minifier\MinifierHelper::class));
            return $helpers;
        });
    }

Is this correct way?

regards..

RobinRadic commented 6 years ago

Hello,

This should be fixed in 7.1.

For 7.0 your fix is correct.