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

[4.x] Show warning when manifest is outdated #783

Merged
merged 3 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
</div>

<div class="col-10">
@if (! $assetsAreCurrent)
<div class="alert alert-warning">
The published Horizon assets are not up-to-date with the installed version. To update, run:<br/><code>php artisan horizon:publish</code>
</div>
@endif

<router-view></router-view>
</div>
</div>
Expand Down
20 changes: 20 additions & 0 deletions src/Horizon.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Closure;
use Exception;
use Illuminate\Support\Facades\File;
use RuntimeException;

class Horizon
{
Expand Down Expand Up @@ -169,4 +171,22 @@ public static function routeSmsNotificationsTo($number)

return new static;
}

/**
* Determine if Horizon's published assets are up-to-date.
*
* @return bool
*
* @throws \RuntimeException
*/
public static function assetsAreCurrent()
{
$publishedPath = public_path('vendor/horizon/mix-manifest.json');

if (! File::exists($publishedPath)) {
throw new RuntimeException('Horizon assets are not published. Please run: php artisan horizon:publish');
}

return File::get($publishedPath) === File::get(__DIR__.'/../public/mix-manifest.json');
}
}
3 changes: 2 additions & 1 deletion src/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class HomeController extends Controller
/**
* Single page application catch-all route.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
return view('horizon::layout', [
'cssFile' => Horizon::$useDarkTheme ? 'app-dark.css' : 'app.css',
'horizonScriptVariables' => Horizon::scriptVariables(),
'assetsAreCurrent' => Horizon::assetsAreCurrent(),
]);
}
}