48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\PaymentMethod;
|
|
use App\Enums\PaymentStatus;
|
|
use App\Models\Order;
|
|
use App\Models\Payment;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class PaymentFactory extends Factory
|
|
{
|
|
protected $model = Payment::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'order_id' => Order::factory(),
|
|
'user_id' => User::factory(),
|
|
'method' => $this->faker->randomElement(PaymentMethod::cases()),
|
|
'amount' => $this->faker->numberBetween(20000, 400000),
|
|
'paid_at' => $this->faker->dateTimeBetween('-7 days', 'now'),
|
|
'status' => $this->faker->randomElement(PaymentStatus::cases()),
|
|
];
|
|
}
|
|
|
|
public function cash(): Factory
|
|
{
|
|
return $this->state(fn () => ['method' => PaymentMethod::CASH]);
|
|
}
|
|
|
|
public function transfer(): Factory
|
|
{
|
|
return $this->state(fn () => ['method' => PaymentMethod::TRANSFER]);
|
|
}
|
|
|
|
public function paid(): Factory
|
|
{
|
|
return $this->state(fn () => ['status' => PaymentStatus::PAID]);
|
|
}
|
|
|
|
public function pending(): Factory
|
|
{
|
|
return $this->state(fn () => ['status' => PaymentStatus::PENDING]);
|
|
}
|
|
}
|