F
Filamentβ€’16mo ago
skybert

(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
skybert
skybertOPβ€’16mo ago
Is there any way to manually load CSS/JS Without using the blade directives? No one?
KA
KAβ€’16mo ago
change config.tenancy.filesystem.asset_helper_tenancy to false
jonathancoates
jonathancoatesβ€’16mo ago
Hey @skybert How did you get around the middleware problem? I can no longer set the InitializeTenancyByDomainOrSubdomain::class middlware in the filament config?
skybert
skybertOPβ€’16mo ago
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
jonathancoates
jonathancoatesβ€’16mo ago
How do you do that in the AppServiceProvider? Can you share your code?
skybert
skybertOPβ€’16mo ago
In boot method:
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/livewire/update', $handle)
->middleware(['web', 'universal', InitializeTenancyByDomainOrSubdomain::class]);
});
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/livewire/update', $handle)
->middleware(['web', 'universal', InitializeTenancyByDomainOrSubdomain::class]);
});
This makes Livewire v3 use the middleware You may need to adjust as i have some more middlewares there πŸ™‚
Dennis Koch
Dennis Kochβ€’16mo ago
Most config is now set via the PanelProvider: $panel->middleware()
jonathancoates
jonathancoatesβ€’16mo ago
@skybert it's still trying to load users from the central db
skybert
skybertOPβ€’16mo ago
Then you have not setup tenancy as you should πŸ™‚ Then the error is in stancl\tenancy not Filament
jonathancoates
jonathancoatesβ€’16mo ago
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
skybert
skybertOPβ€’16mo ago
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
jonathancoates
jonathancoatesβ€’16mo ago
is /livewire/update a custom thing, or default ? I don't think that actually did anything... wondering if I'm missing something?
skybert
skybertOPβ€’16mo ago
/livewire/update is the route livewire uses when it goes to update data, default
skybert
skybertOPβ€’16mo ago
Laravel
Installation | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
skybert
skybertOPβ€’16mo ago
Are you using path or subdomain identification btw?
jonathancoates
jonathancoatesβ€’16mo ago
It sometimes uses subdomain, sometimes domain..
skybert
skybertOPβ€’16mo ago
I know there is an issue with path identification since livewire cant parse path variables
jonathancoates
jonathancoatesβ€’16mo ago
so I have InitializeTenancyByDomainOrSubdomain middleware
Dennis Koch
Dennis Kochβ€’16mo ago
@jonathancoates Please send your panel configuration
jonathancoates
jonathancoatesβ€’16mo ago
@Dennis Koch What is that, where is that? Oh app/Providers/Filament/AdminPanelProvider.php ??
Dennis Koch
Dennis Kochβ€’16mo ago
Yes
jonathancoates
jonathancoatesβ€’16mo ago
Agh there's middleware there... Let me try that
Dennis Koch
Dennis Kochβ€’16mo ago
That's what I just said
jonathancoates
jonathancoatesβ€’16mo ago
Haha sorry! Let me try. Wahey that works! Thanks @Dennis Koch
Dennis Koch
Dennis Kochβ€’16mo ago
Please make sure you read the upgrade guide. It's there for a reason: https://filamentphp.com/docs/3.x/panels/upgrade-guide
jonathancoates
jonathancoatesβ€’16mo ago
Yup... where in that guide does it say anything about middleware? I don't see it.
Dennis Koch
Dennis Kochβ€’16mo ago
No, but it mentions the PanelProvider. Did you run the upgrade script? Maybe that's missing the middleware config.
jonathancoates
jonathancoatesβ€’16mo ago
Yeah I ran the upgrade script, doesn't fix it... so the docs aren't helpful in this case πŸ™‚
Dennis Koch
Dennis Kochβ€’16mo ago
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,
jonathancoates
jonathancoatesβ€’16mo ago
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,
jonathancoates
jonathancoatesβ€’16mo ago
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 works
Dennis Koch
Dennis Kochβ€’16mo ago
Interesting. Sounds like a LW bug if it’s using a different middleware than other LW routes though.
Mohamed Melouk
Mohamed Meloukβ€’15mo ago
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 styling
Dennis Koch
Dennis Kochβ€’15mo ago
You need to use the tenant_asset() helper then
vas
vasβ€’12mo ago
got 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
Want results from more Discord servers?
Add your server