Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blade directives not working #153

Open
maxacarvalho opened this issue Mar 6, 2022 · 3 comments
Open

Blade directives not working #153

maxacarvalho opened this issue Mar 6, 2022 · 3 comments

Comments

@maxacarvalho
Copy link

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.

@lukepower
Copy link

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

@drbyte
Copy link
Contributor

drbyte commented Jul 26, 2023

#159 should resolve this.

ohnotnow pushed a commit to UoGSoE/examdb that referenced this issue Nov 6, 2023
@rforced
Copy link

rforced commented Jan 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants