Files
fotospiel-app/database/factories/CouponFactory.php

52 lines
1.5 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\CouponStatus;
use App\Enums\CouponType;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Coupon>
*/
class CouponFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$type = $this->faker->randomElement([
CouponType::PERCENTAGE,
CouponType::FLAT,
]);
$amount = $type === CouponType::PERCENTAGE
? $this->faker->numberBetween(5, 40)
: $this->faker->numberBetween(5, 150);
return [
'name' => $this->faker->words(3, true),
'code' => Str::upper(Str::random(8)),
'type' => $type,
'amount' => $amount,
'currency' => $type === CouponType::PERCENTAGE ? null : 'EUR',
'status' => CouponStatus::ACTIVE,
'is_stackable' => false,
'enabled_for_checkout' => true,
'auto_apply' => false,
'usage_limit' => 100,
'per_customer_limit' => 1,
'description' => $this->faker->sentence(),
'metadata' => ['note' => 'factory'],
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'paddle_discount_id' => 'dsc_'.Str::upper(Str::random(10)),
'paddle_mode' => 'standard',
];
}
}