Can't add scripts to admin panel service provider
I tried adding the scripts as indicated here, but it doesn't appear on any part of the filament admin app.
For context, I am on a Laravel 11 app that uses Volt. But the file is still just a JS file sitting in that resources folder.
https://filamentphp.com/docs/3.x/support/assets#registering-javascript-files
Solution:Jump to solution
Looks like using
asset()
is the proper way to do this to prevent copying the files.
```
class AdminPanelProvider extends PanelProvider
{...19 Replies
you can add it to the AppServiceProvider or use
$panel->bootUsing(function(){ ... })
I did add that to the app service provider. It seemed like that didn't add it either.
How would this work in bootUsing? Same call?
did you run
php artisan filament:assets
?This would be my full AppServiceProvider file. Any other steps to make sure it's imported?
I did
That puts it in
public/js/app/app.js
that's it
Why's that?
wasn't it imported?
No, once it's put in there, there's nothing on the admin side that looks for it.
The main laravel site is already importing it with Volt.
Is there a step to make Filament actually use the assets it finds from there? Is there a main layout page I'm supposed to edit?
if you add a
console.log('Hello, world!')
to app.js, it should appear on each page in your panelI added an alert there but nothing comes up. When I search the inspector, that script isn't loaded.
run
php artisan filament:assets
clear the cache
if you are optimizing Filament, try to run php artisan filament:optimize-clear
Nothing.
I think I will use a widget for now to get the script on the page.
hum.. it should work
Maybe there's something funky. Just seems like the filament:assets command is moving the file but nothing is doing the automatic import.
Maybe this is a difference between how Breeze now sets up Volt apps and what Filament expects the structure to be
If you are able to create a minimal repo on github to reproduce this issue, I can take a look later
I will try, thank you
Having trouble getting scripts to execute in a widget as well. Is there a quick and dirty workaround to just defining a small JS function somewhere?
?
Thank you, got it on the widget
I'm realizing what happened.
They had imports at the top, so filament was trying to load them and ran into an error.
Laravel breeze sets up Vite to compile these with babel, but filament obviously doesn't do that.
So how should I do this with filament? I don't want to add the outputted vite built JS file to the FilamentAsset because then filament will collect it and put it in the public folder again
Or is that fine
Solution
Looks like using
asset()
is the proper way to do this to prevent copying the files.