Skip to content

Instantly share code, notes, and snippets.

@abishekrsrikaanth
Last active July 29, 2021 03:25
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/55d15f6040cf43f54708c95e9f63e06d to your computer and use it in GitHub Desktop.
Save abishekrsrikaanth/55d15f6040cf43f54708c95e9f63e06d 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')) {
$user = $request->user();
if ($user) {
$user->loadMissing('plan');
$plan = $user->plan;
if($plan) {
app('config')->set('spark.billables.team.plans', [
[
'name' => $plan->name,
'short_description' => $plan->description,
'monthly_id' => $plan->stripe_plan_id,
'features' => $plan->features,
],
]
);
}
}
}
return $request->user()->currentTeam;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment