Created
July 29, 2021 03:33
-
-
Save abishekrsrikaanth/f6ece78459a5b6c16291eccdf20cb1dd 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')) { | |
$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