Created
December 16, 2023 14:02
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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