(Manually load JS/CSS) Filament v3 & stancl/tenancy
Hi there!
I am trying to get the Filament Form Builder v3 to work with stancl/tenancy, but are getting some issues when trying to use
@filamentStyles
and @filamentScripts
. When they are present in my layout i get an exception from stancl\tenancy that "Tenant could not be identified on domain test1.app.domain.com"
In v2 this does not seem to be a problem and the package is explicitly documented here: https://filamentphp.com/docs/2.x/admin/resources/getting-started#stancltenancy
I have tried as close as possible to replicate the instructions there, and have made Livewire v3 work as it should, but the issue is isolated to the Filament Asset Manager and when it loads the registered assets.
Any suggestions for a remedy that can make this exception go away?36 Replies
Is there any way to manually load CSS/JS Without using the blade directives?
No one?
change
config.tenancy.filesystem.asset_helper_tenancy
to false
Hey @skybert How did you get around the middleware problem? I can no longer set the
InitializeTenancyByDomainOrSubdomain::class
middlware in the filament config?Hey!, had some discussions and ended up as @itskawsar41 said, changing the config file for stancl/tenancy to no longer "hijack" the asset helper, so the asset helper works as expected for 3rd party apps and loses concept of tenancy.
That makes the @Filament stuff work as it should, and for setting the middleware in livewire, add the stuff according to livewire docs in AppServiceProvider
How do you do that in the AppServiceProvider?
Can you share your code?
In boot method:
This makes Livewire v3 use the middleware
You may need to adjust as i have some more middlewares there π
Most config is now set via the PanelProvider:
$panel->middleware()
@skybert it's still trying to load users from the central db
Then you have not setup tenancy as you should π
Then the error is in stancl\tenancy not Filament
No I have... this is an existing project that was working before π
The middleware isn't being loaded, because that's what identifies the tenant
Hmm, works for me with this way, it hits the tenant DB
What i recommend you do is possibly install clockwork and see exactly what routes dont get the MW
is
/livewire/update
a custom thing, or default ?
I don't think that actually did anything... wondering if I'm missing something?/livewire/update is the route livewire uses when it goes to update data, default
Laravel
Installation | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Are you using path or subdomain identification btw?
It sometimes uses subdomain, sometimes domain..
I know there is an issue with path identification since livewire cant parse path variables
so I have
InitializeTenancyByDomainOrSubdomain
middleware@jonathancoates Please send your panel configuration
@Dennis Koch What is that, where is that?
Oh
app/Providers/Filament/AdminPanelProvider.php
??Yes
Agh there's middleware there...
Let me try that
That's what I just said
Haha sorry!
Let me try.
Wahey that works!
Thanks @Dennis Koch
Please make sure you read the upgrade guide. It's there for a reason:
https://filamentphp.com/docs/3.x/panels/upgrade-guide
Yup... where in that guide does it say anything about middleware?
I don't see it.
No, but it mentions the PanelProvider. Did you run the upgrade script? Maybe that's missing the middleware config.
More on the new configuration method here:
https://filamentphp.com/docs/3.x/panels/configuration
Yeah I ran the upgrade script, doesn't fix it...
so the docs aren't helpful in this case π
Summary for everyone coming here:
- Add middleware to your panels:
$panel->middleware([InitializeTenancyByDomainOrSubdomain::class])
- Add middleware to livewire: https://livewire.laravel.com/docs/installation#configuring-livewires-update-endpoint
- Optionally: Disable tenant asset helper: 'config.tenancy.filesystem.asset_helper_tenancy' => false,
You don't need to do the first part I don't think, I haven't needed too...
Disable tenant asset helper: 'config.tenancy.filesystem.asset_helper_tenancy' => false,
Further to this issue, I found that FileUpload's don't work because the livewire
upload-file
route has the wrong middleware, there doesn't seem to be a way to update this with livewire?
Nvm fixed, I just added InitializeTenancyByDomainOrSubdomain
to the web
middleware in the middleware groups...
not sure if this is a bad idea or not
but it worksInteresting. Sounds like a LW bug if itβs using a different middleware than other LW routes though.
If I disabled
config.tenancy.filesystem.asset_helper_tenancy
it will break all my uploaded images for each tenant, How to get around that?
if I keep it true
it breaks filament assets, admin loads without stylingYou need to use the
tenant_asset()
helper thengot pretty much the same issue here https://discord.com/channels/883083792112300104/1180409835309764628
file upload works but the img preview dont as see in the post
anyone else got this issue or if it works for you i would like to hear from you thanks