F
Filament2y ago
Ashk

Global resources in tenant

Hello, I'm using tenant, I would like to know if it's possible to have "global resources". What I mean by that is: - resources common to all tenants - ideally with a generic URL without the tenant ID
8 Replies
Patrick Boivin
Can you put the shared resources in a different panel?
Ashk
AshkOP2y ago
@pboivin Yes, I want to give possibility in all tenant to manage resources outside their tenant Example : - ServerResource : global resources, don't belong to a tenant : /servers - UserResource : belongto tenant : /{tenant}/users But I take a look to the code and I think it's not really possible
josef
josef2y ago
global resources should be possible if you re-implement the getTenantResources() on your resource to not scope it to the tenant as for generic url, right now there's no setting or anything for that, but you could create a panel without a name and tenancy and put your resources there, then let all users access that panel. not sure if that would work, but that's what I would try somehow didnt see your reply. so for servers, create a tenant-less panel and put the global resources there, for all others use the tenant. then you just have to figure out how to navigate users between the panels
Ashk
AshkOP2y ago
It's possible but, I would like to keep current tenant navigation + global navigation. If I create another panel I lose this behaviour I didn't find a way to keep a good UX with 2 differents panels. I create a ServerResource, a override the tenant scope to always have the same query and it's good. The only problem, the url : /{tenant}/servers but it's ok for the moment
F alko
F alko2y ago
For those who are trying this, just add this to your resource.
public static function scopeEloquentQueryToTenant(Builder $query, Model|null $tenant): Builder
{
return $query;
}
public static function scopeEloquentQueryToTenant(Builder $query, Model|null $tenant): Builder
{
return $query;
}
Ashk
AshkOP2y ago
Yeah, I did something like
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

trait SharedTenantResource
{
public static function scopeEloquentQueryToTenant(Builder $query, ?Model $tenant): Builder
{
return $query;
}
}
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

trait SharedTenantResource
{
public static function scopeEloquentQueryToTenant(Builder $query, ?Model $tenant): Builder
{
return $query;
}
}
But I didn't find a way to change the url to /{tenant}/my-resource to /my-resource
Andrew Wallo
Andrew Wallo2y ago
If the Resource doesn't belong to the tenant panel, then you shouldn't be getting that error. Make sure the Resource is created within the Global panel you have.
F alko
F alko2y ago
We are abusing the multitenancy for tool environments. So for product data we need the resource to be global, but accessible from the tenant panel.

Did you find this page helpful?