Last active
July 29, 2021 03:25
-
-
Save abishekrsrikaanth/55d15f6040cf43f54708c95e9f63e06d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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