From 76ac1bc81a45e9e5a943ba379403b61e232d0842 Mon Sep 17 00:00:00 2001 From: Choraimy Kroonstuiver Date: Thu, 9 Jan 2020 11:42:18 +0100 Subject: [PATCH] No longer instantiate the blade compiler if its not instantiated by the framework --- src/ZiggyServiceProvider.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ZiggyServiceProvider.php b/src/ZiggyServiceProvider.php index dd7496a9..18e6ea76 100644 --- a/src/ZiggyServiceProvider.php +++ b/src/ZiggyServiceProvider.php @@ -18,9 +18,13 @@ public function boot() return Macro::whitelist($this, $group); }); - $this->app['blade.compiler']->directive('routes', function ($group) { - return "generate({$group}); ?>"; - }); + if ($this->app->resolved('blade.compiler')) { + $this->registerDirective($this->app['blade.compiler']); + } else { + $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { + $this->registerDirective($bladeCompiler); + }); + } if ($this->app->runningInConsole()) { $this->commands([ @@ -28,4 +32,11 @@ public function boot() ]); } } + + protected function registerDirective(BladeCompiler $bladeCompiler) + { + $bladeCompiler->directive('routes', function ($group) { + return "generate({$group}); ?>"; + }); + } }