From 831fb0256f2f10438f4c11b4a0acd737dcec90a0 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Sun, 14 Feb 2021 22:19:52 +0000 Subject: [PATCH] Add asset ID from mix --- .../views/components/layouts/base.blade.php | 10 +++++++-- src/helpers.php | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/resources/views/components/layouts/base.blade.php b/resources/views/components/layouts/base.blade.php index 048d6999c..883663825 100644 --- a/resources/views/components/layouts/base.blade.php +++ b/resources/views/components/layouts/base.blade.php @@ -10,7 +10,10 @@ @livewireStyles - + @stack('filament-styles') @@ -20,7 +23,10 @@ @livewireScripts - + @stack('filament-scripts') diff --git a/src/helpers.php b/src/helpers.php index 47128ce01..e338e8e04 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -2,6 +2,7 @@ namespace Filament; +use Illuminate\Support\Str; use League\Glide\Urls\UrlBuilderFactory; if (! function_exists('Filament\format_attributes')) { @@ -27,6 +28,27 @@ function format_bytes($size, $precision = 0) } } +if (! function_exists('Filament\get_asset_id')) { + function get_asset_id($path) + { + $manifestPath = __DIR__.'/../dist/mix-manifest.json'; + + if(! file_exists($manifestPath)) return null; + + $manifest = json_decode(file_get_contents($manifestPath), true); + + if (! array_key_exists($path, $manifest)) return null; + + $path = $manifest[$path]; + + if (! str_contains($path, 'id=')) return null; + + $id = (string) Str::of($path)->after('id='); + + return $id; + } +} + if (! function_exists('Filament\get_image_url')) { function get_image_url($path, $manipulations = []) {