<?php
namespace App\Providers;
use App\Models\Team;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\ValidationException;
use Spark\Plan;
use Spark\Spark;
use Laravel\Cashier\Cashier;
use Filament\Facades\Filament;
class SparkServiceProvider extends ServiceProvider
{
public function register(): void
{
Spark::ignoreMigrations();
}
public function boot(): void
{
// Instruct Cashier to use the `Team` model instead of the `User` model...
Cashier::useCustomerModel(Team::class);
// Resolve the current team...
Spark::billable(Team::class)->resolve(function (Request $request) {
return $request->user()->currentTeam;
});
// Verify that the current user owns the team...
Spark::billable(Team::class)->authorize(function (Team $billable, Request $request) {
return $request->user() &&
$request->user()->team_id == $billable->team_id;
});
Spark::billable(Team::class)->checkPlanEligibility(function (Team $billable, Plan $plan) {
// if ($billable->projects > 5 && $plan->name == 'Basic') {
// throw ValidationException::withMessages([
// 'plan' => 'You have too many projects for the selected plan.'
// ]);
// }
});
}
}