Skip to content

Instantly share code, notes, and snippets.

@neverything
Created December 16, 2023 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverything/d1dc6d885973b54479f65e31896f71e0 to your computer and use it in GitHub Desktop.
Save neverything/d1dc6d885973b54479f65e31896f71e0 to your computer and use it in GitHub Desktop.
Extending the Filament Middleware to verify if a tenant is billable. Read more and learn an even better way: https://silvanhagen.com/free-users-filament-laravel-spark/
<?php
namespace App\Http\Middleware;
use Filament\Billing\Providers\Http\Middleware\VerifySparkBillableIsSubscribed;
use Filament\Facades\Filament;
class VerifyProjectIsBillable extends VerifySparkBillableIsSubscribed
{
public function handle($request, $next, $subscription = 'default', $plan = null)
{
$project = Filament::getTenant();
if ($this->shouldRedirectToBilling($project, $request)) {
return parent::handle($request, $next, $subscription, $plan);
}
return $next($request);
}
protected function shouldRedirectToBilling($project, $request): bool
{
return $project
&& $project->isBillable()
&& ! $project->isOnTrialOrSubscribed();
&& $request->route()->named([
'filament.admin.resources.feedback.index',
'filament.admin.resources.feedback.create',
'filament.admin.resources.feedback.edit',
'filament.admin.resources.feedback.show',
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment