51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\ExpenseType;
|
|
use App\Models\Expense;
|
|
use App\Models\Outlet;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class ExpenseFactory extends Factory
|
|
{
|
|
protected $model = Expense::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'outlet_id' => Outlet::factory(),
|
|
'amount' => $this->faker->numberBetween(10000, 200000),
|
|
'description' => $this->faker->sentence(6),
|
|
'type' => $this->faker->randomElement(ExpenseType::cases()),
|
|
];
|
|
}
|
|
|
|
public function operational(): Factory
|
|
{
|
|
return $this->state(fn () => ['type' => ExpenseType::OPERATIONAL]);
|
|
}
|
|
|
|
public function purchase(): Factory
|
|
{
|
|
return $this->state(fn () => ['type' => ExpenseType::PURCHASE]);
|
|
}
|
|
|
|
public function salary(): Factory
|
|
{
|
|
return $this->state(fn () => ['type' => ExpenseType::SALARY]);
|
|
}
|
|
|
|
public function today(): Factory
|
|
{
|
|
return $this->state(fn () => ['created_at' => now()]);
|
|
}
|
|
|
|
public function yesterday(): Factory
|
|
{
|
|
return $this->state(fn () => ['created_at' => now()->subDay()]);
|
|
}
|
|
}
|