laravel-impersonate icon indicating copy to clipboard operation
laravel-impersonate copied to clipboard

Blade directives not working

Open maxacarvalho opened this issue 2 years ago • 3 comments

I noticed that the Blade directives such as @impersonating() and @endImpersonating() stooped working, instead they were being rendered as HTML on the frontend.

After some digging and debugging I found out that the "problem" lies in the way that the directives are registered.
I also found a way to fix the issue, but I admit that I'm not sure about the technical reason behind the problem, I didn't have time to dig more into it.

Note: The issue started after the Laravel 9 upgrade.

Actual implementation:

   public function register()
    {
        ...
        $this->registerBladeDirectives();
        ...
    }

    protected function registerBladeDirectives()
    {
        $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
            /// register the Blade directives
        });
    }

My fix:

    public function boot(): void
    {
        ...
        if ($this->app->resolved('blade.compiler')) {
            $this->registerImpersonateDirectives($this->app['blade.compiler']);
        } else {
            $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
                $this->registerImpersonateDirectives($bladeCompiler);
            });
        }

What also works: If it's really necessary to place the directive declaration inside the register method, do not wrap it with the ...afterResolving('blade.compiler',... callback, that also worked with my tests.

maxacarvalho avatar Mar 06 '22 20:03 maxacarvalho

Is there a fix for this? I updated to Laravel 10 but cannot use the blade directives

lukepower avatar Jul 05 '23 19:07 lukepower

https://github.com/404labfr/laravel-impersonate/pull/159 should resolve this.

drbyte avatar Jul 26 '23 01:07 drbyte

Any update to this? This still does not work on laravel 10

rforced avatar Jan 24 '24 21:01 rforced