38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\Subscription;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class SubscriptionFactory extends Factory
|
|
{
|
|
public function definition(): array
|
|
{
|
|
$start = now()->startOfMonth();
|
|
|
|
return array_merge(Subscription::snapshotFrom('team'), [
|
|
'customer_id' => Customer::factory(),
|
|
'started_at' => $start,
|
|
'current_period_start' => $start,
|
|
'current_period_end' => $start->copy()->addMonth(),
|
|
'status' => 'active',
|
|
]);
|
|
}
|
|
|
|
public function plan(string $plan, string $term = Subscription::TERM_MONTHLY): static
|
|
{
|
|
return $this->state(function () use ($plan, $term) {
|
|
$start = now()->startOfMonth();
|
|
|
|
return array_merge(Subscription::snapshotFrom($plan, $term), [
|
|
'current_period_start' => $start,
|
|
'current_period_end' => $term === Subscription::TERM_YEARLY
|
|
? $start->copy()->addYear()
|
|
: $start->copy()->addMonth(),
|
|
]);
|
|
});
|
|
}
|
|
}
|