Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Update AssetInjection.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner authored Aug 31, 2020
1 parent 71ac449 commit 706100d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Http/Middleware/AssetInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ public function handle($request, Closure $next)
{
$response = $next($request);

// return $response;
if (! method_exists($response, 'getContent')) {
return $response;
}

$content = $response->getContent();

if (! is_string($content)) {
if (! $content) {
return $response;
}
$castsScripts = '<script src="' . asset('genealabs-laravel-casts/app.js') . '"></script>';

$castsScripts = '<script src="' . asset('genealabs-laravel-casts/app.js') . '"></script></body>';
$livewireScripts = (new LivewireManager)->scripts();
$livewireStyles = (new LivewireManager)->styles();

$html = new HtmlPageCrawler($content);
$html = (new HtmlPageCrawler)->create($content);

if (! $html) {
return $response;
}

if ($this->isNotOnErrorPage($html)
&& $html->filter("html > head")->count()
) {
if ($html->filter("html > head")->count()) {
$html->filter("html > head")->append($livewireStyles);
$html->filter("html > head")->append($livewireStyles);
$html->filter("html > body")->append($livewireScripts);
$html->filter("html > body")->append($castsScripts);
Expand All @@ -42,9 +44,4 @@ public function handle($request, Closure $next)

return $response;
}

protected function isNotOnErrorPage(string $html) : bool
{
return strpos($html, "window.Ignition") === false;
}
}

0 comments on commit 706100d

Please sign in to comment.