Comments (2)
Filament PHP Admin Panel - Asset Path Challenge in Tenancy Applications
Dear Developers, community,
I hope this message finds you well. Following our discussion on the challenges associated with asset paths in tenancy applications when utilizing Filament PHP as an admin panel, I'm pleased to present a comprehensive solution that I've implemented.
The Issue:
The primary obstacle arises from the dynamic nature of asset paths in tenancy applications. Specifically, when dealing with a tenancy application, the asset path can vary between being a subdomain and an external domain linked to the application. Currently, there are limited references addressing this challenge, prompting me to share my observations and seek community input for potential solutions.
The Solution:
In the AppServiceProvider.php
, within the boot
method, I've incorporated the following code to dynamically handle asset paths:
// Retrieve the domain and subdomain from the cache if available
list($subdomain, $domain) = Cache::remember('current_subdomain_domain', now()->addDay(), function () {
// Parse the URL to extract the host (domain)
$parsedUrl = parse_url(URL::current());
// Get the host (domain) from the parsed URL
$host = $parsedUrl['host'];
// Split the host into subdomain and domain
$segments = explode('.', $host, 2);
$subdomain = isset($segments[0]) ? $segments[0] : null;
$domain = isset($segments[1]) ? $segments[1] : null;
return [$subdomain, $domain];
});
// Cache domain-specific assets path
$assetsPath = Cache::remember("assets_path_$subdomain.$domain", now()->addDay(), function () use ($subdomain, $domain) {
return "https://$subdomain.$domain";
});
config(['filament.assets_path' => $assetsPath]);
\Log::info("Current Subdomain: $subdomain, Current Domain: $domain");
// Check if the current URL is not the same as app.central_domain
if ("$subdomain.$domain" !== config('app.central_url')) {
\Log::info("Condition matched. Adding middleware.");
// Only run the code if the current URL is not the same as central_domain and is a subdomain
Livewire::setUpdateRoute(function ($handle) use ($subdomain, $domain) {
return Route::post('/livewire/update', $handle)
->middleware([
'web',
InitializeTenancyByDomainOrSubdomain::class
]);
});
Artisan::call('route:clear');
}
Feel free to adapt and improve this solution based on your specific application requirements. I encourage the community to provide feedback, suggestions, or enhancements to further refine this approach.
Best regards,
Mohammed B,
from tenancy.
Hey @devhereco, I'm looking for how to implement filament using this tenancy, but I found nothing,
I've got the weird error that the table from the tenant database is not found because the database is still using the central database
I already implemented the InitializeTenancyByDomain::class
in Livewire::setUpdateRoute
method, and then I already initialized the tenant using the subdomain, but I still get that error
$panel = $panel
->id('tenant')
->colors([
'primary' => Color::Amber,
])
->path('/member')
->login()
->discoverResources(in: app_path('Filament/Tenant/Resources'), for: 'App\\Filament\\Tenant\\Resources')
->discoverPages(in: app_path('Filament/Tenant/Pages'), for: 'App\\Filament\\Tenant\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Tenant/Widgets'), for: 'App\\Filament\\Tenant\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
$url = request()->getHost();
$domain = explode('.', $url);
if (count($domain) > 2) {
tenancy()->initialize($domain[0]);
$tenant = tenancy()->tenant;
$subdomain = $tenant?->domains?->first()?->domain;
$panel
->domain($subdomain);
}
return $panel;
I'm pleased if you can help solve my issue Thanks;
from tenancy.
Related Issues (20)
- Reset Password for Tenant not working HOT 1
- Preventing Timestamps from Being Auto-inserted into the data Column HOT 1
- Unable to seed spatie/laravel permission across multiple tenancy databases HOT 5
- Undefined constant RedisCluster::OPT_PREFIX HOT 5
- With laravel breeze and react ,Inertia.js not working after installing the package HOT 1
- Wrong domain url when on queue HOT 2
- Jestream Laravel Tenacy HOT 5
- InitializeTenancyByPath with livewire within tenant context throws exception HOT 8
- Make runForMultiple yield the callbacks return HOT 5
- Sugestion new Middleware
- Pass tenant to handle when using TenantAwareCommand trait HOT 2
- Route helper in job doesn't use tenant context domain HOT 5
- Tenancy is not working for Livewire HOT 4
- Nested sub domain HOT 3
- Could Not Switch tenants when using Aritsan command HOT 1
- 3.8.3 ViteBundler incompatibility with Laravel 9 HOT 3
- laravel 10 support HOT 1
- LOG.warning tenantIdColumn is deprecated HOT 1
- PostgreSQL Tenant Database Not Automatically Created During Tenant Creation
- Call to a member function getTenantKey() on null HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tenancy.