Files
besttechfrom.eu/database/factories/ProductFactory.php
T

78 lines
1.8 KiB
PHP
Raw Normal View History

2026-02-07 14:36:33 +02:00
<?php
namespace Database\Factories;
use App\Models\Category;
use App\Models\Product;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product>
*/
class ProductFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Product::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'title' => $this->faker->sentence(3),
'description' => $this->faker->paragraph(),
'website_url' => $this->faker->url(),
'thumbnail' => null,
'user_id' => User::factory(),
'category_id' => Category::factory(),
'status' => 'pending',
'approved_at' => null,
'rejected_at' => null,
];
}
/**
* Indicate that the product is approved.
*/
public function approved(): static
{
return $this->state(fn (array $attributes) => [
'status' => 'approved',
'approved_at' => now(),
'rejected_at' => null,
]);
}
/**
* Indicate that the product is pending.
*/
public function pending(): static
{
return $this->state(fn (array $attributes) => [
'status' => 'pending',
'approved_at' => null,
'rejected_at' => null,
]);
}
/**
* Indicate that the product is rejected.
*/
public function rejected(): static
{
return $this->state(fn (array $attributes) => [
'status' => 'rejected',
'approved_at' => null,
'rejected_at' => now(),
]);
}
}