Donnell Wyche
Donnell Wyche
FFilament
Created by Donnell Wyche on 11/29/2023 in #❓┊help
ImportAction Infinite Loop when using the new FilamentPHP 3.1 Import Action
Created an Importer, ran it, then got a flood of failed jobs because of this error in the vendor/filament/actions/src/Imports/Models/Import.php file on line 43: Cannot use "::class" on value of type null array:1 [▶ "exception" => TypeError {#4305▶ #message: "Cannot use "::class" on value of type null" #code: 0 #file: "vendor/filament/actions/src/Imports/Models/Import.php" #line: 43 } ] I'm using Laravel 10.34.2, PHP 8.2.12, Filament 3.1 with Multi-tenancy. As best I can tell, this function isn't resolving the User model as the Authenticatable class. --- My User model is class User extends Authenticatable implements FilamentUser, HasAvatar, HasTenants
26 replies
FFilament
Created by Donnell Wyche on 10/30/2023 in #❓┊help
Integrating Multi-Tenancy with Laravel Spark: Handling Subscriptions and Trial Periods
What I am trying to do: I am integrating FilamentPHP's multi-tenancy features with Laravel Spark. I want to ensure that the application correctly handles trial periods as configured in Laravel Spark. This solution works. What I did: I implemented a custom middleware named CheckTenantSubscription to check whether a tenant has an active subscription or is within their trial period, redirecting them to the billing page if neither condition is met. In this middleware, I used Filament::getTenant() to retrieve the tenant's information, and then proceeded to check their subscription status and trial period against the current date and time. My issue/the error: Using FilamentPHP's ->requiresTenantSubscription() seems to ignore Laravel Spark’s trial period. I expected it to consider the trial period automatically during subscription checks. In my middleware, I’ve explicitly handled trial and subscription checks. However, I’m uncertain if this aligns with FilamentPHP standards, especially when integrated with Laravel Spark. I am looking for guidance on whether there is a standard or more "Filament" way to handle this scenario. Code:
public function handle(Request $request, Closure $next): Response
{
$tenant = Filament::getTenant();

if (!$tenant) {
return $next($request);
}

// Check if the tenant is within their trial period
if ($tenant->trial_ends_at && Carbon::now()->lessThan($tenant->trial_ends_at)) {
return $next($request);
}

// Check for active subscription
if (!$tenant->subscribed()) {
return redirect()->route('spark.portal', ['type' => 'team', 'id' => $tenant->id]);
}

return $next($request);
}
public function handle(Request $request, Closure $next): Response
{
$tenant = Filament::getTenant();

if (!$tenant) {
return $next($request);
}

// Check if the tenant is within their trial period
if ($tenant->trial_ends_at && Carbon::now()->lessThan($tenant->trial_ends_at)) {
return $next($request);
}

// Check for active subscription
if (!$tenant->subscribed()) {
return redirect()->route('spark.portal', ['type' => 'team', 'id' => $tenant->id]);
}

return $next($request);
}
4 replies