404labfr / 404labfr/laravel-impersonate

Blade directives not working

オープン
#153 コメント 3 件 リアクション 3 件 担当者 0 名 GitHub で見る
bug next version
主要言語
PHP
スター
2.3k
フォーク
235
PR マージ指標
30日以内にマージされた PR はありません

説明

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:**
```php
public function register()
{
...
$this->registerBladeDirectives();
...
}

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

**My fix:**
```php
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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。