F
Filamentβ€’12mo ago
neverything

Is there a way to get the current tenant in isTenantSubscriptionRequired()?

For a Resource in the Panel, I need to get the current tenant and when implementing isTenantSubscriptionRequired(Panel $panel) using Filament::getTenant() returns null. Is there a way to get the current tenant from the $panel passed to the method in the Resource?
Solution:
Thanks to the Filament team helping me on twitter, I was able to implement a much nicer solution. Here is how: https://silvanhagen.com/writing/free-users-filament-laravel-spark/
Silvan Hagen
Handle free users with Filament and Laravel Spark
How to handle free users in a multi-tenant Filament app using Laravel Spark and a custom Middleware.
Jump to solution
2 Replies
neverything
neverythingOPβ€’12mo ago
public static function isTenantSubscriptionRequired(Panel $panel): bool
{
$path = request()->path();

if (! preg_match('/project\/(\d+)/', $path, $matches)) {
return true;
}

$tenant = $panel->getTenantModel()::findOrFail(intval($matches[1]));

return $tenant->isBillable();
}
public static function isTenantSubscriptionRequired(Panel $panel): bool
{
$path = request()->path();

if (! preg_match('/project\/(\d+)/', $path, $matches)) {
return true;
}

$tenant = $panel->getTenantModel()::findOrFail(intval($matches[1]));

return $tenant->isBillable();
}
The above does work, but it's very very ugly. If anyone knows about a better way, feel free to share πŸ˜„
Solution
neverything
neverythingβ€’12mo ago
Thanks to the Filament team helping me on twitter, I was able to implement a much nicer solution. Here is how: https://silvanhagen.com/writing/free-users-filament-laravel-spark/
Silvan Hagen
Handle free users with Filament and Laravel Spark
How to handle free users in a multi-tenant Filament app using Laravel Spark and a custom Middleware.
Want results from more Discord servers?
Add your server