Demonstrates how to have "premium" menu items which are shown on the sidebar but lead to "locked" pages with buttons to pay for premium.
It's inspired by a question on the official Filament Discord:
So, this project shows four Filament Resources:
Notice 1: The project doesn't implement the payments/subscriptions. It's simplified and focused on just menu items show/hide, using just users.is_subscribed
DB column.
Notice 2: those resources are also "placeholders", without any DB data or Filament columns/inputs, just to show the situation.
If a non-subscribed user clicks on any Paid resource, they are redirected to the speficic Locked page, with the resource as a part of the URL, for future redirect after the payment.
To check each page for access, there's a global SubscriptionMiddleware
assigned to all Filament routes.
app/Http/Middleware/SubscriptionMiddleware.php:
class SubscriptionMiddleware{ private array $paidResources = [ 'tags', 'projects', 'categories', ]; /** * Handle an incoming request. * * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next */ public function handle(Request $request, Closure $next): Response { if (!auth()->user()->is_subscribed) { // ...