Skip to content

Instantly share code, notes, and snippets.

@abishekrsrikaanth
Created July 29, 2021 03:33
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 abishekrsrikaanth/f6ece78459a5b6c16291eccdf20cb1dd to your computer and use it in GitHub Desktop.
Save abishekrsrikaanth/f6ece78459a5b6c16291eccdf20cb1dd to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use App\Models\StripePlan;
use App\Models\Team;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\ValidationException;
use Spark\Plan;
use Spark\Spark;
class SparkServiceProvider extends ServiceProvider
{
public function boot(): void
{
Spark::billable(Team::class)->resolve(function (Request $request) {
if (Schema::hasTable('stripe_plans')) {
$plans = self::all();
$mappedPlans = [];
$plans->map(function ($plan) use (&$mappedPlans) {
$mappedPlans[] = [
'name' => $plan->name,
'short_description' => $plan->description,
'monthly_id' => $plan->stripe_plan_id,
'features' => explode(' | ', $plan->features),
];
});
app('config')->set('spark.billables.team.plans', $mappedPlans);
}
return $request->user()->currentTeam;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment