simedkom/database/factories/NewsFactory.php
Yoga Pangestu 2c5b057958 feat(news): implement news resource with CRUD functionality
- Created NewsResource for managing news entries.
- Added pages for creating, editing, and listing news.
- Defined NewsForm schema for news entry forms.
- Configured NewsTable for displaying news records with actions.
- Implemented News model with relationships and soft deletes.
- Added factories for generating test data for news and tags.
- Created migrations for news and tags tables.
2025-12-12 09:48:34 +07:00

66 lines
1.5 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\News;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\News>
*/
class NewsFactory extends Factory
{
protected $model = News::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$title = $this->faker->sentence(6);
return [
'author_id' => User::factory(),
'title' => $title,
'slug' => Str::slug($title),
'content' => $this->faker->paragraphs(3, true),
'link' => $this->faker->optional(0.3)->url(),
'view' => $this->faker->numberBetween(0, 10000),
];
}
/**
* Indicate that the news has high views.
*/
public function popular(): static
{
return $this->state(fn (array $attributes) => [
'view' => $this->faker->numberBetween(5000, 50000),
]);
}
/**
* Indicate that the news has external link.
*/
public function withLink(): static
{
return $this->state(fn (array $attributes) => [
'link' => $this->faker->url(),
]);
}
/**
* Indicate that the news has no views.
*/
public function unpublished(): static
{
return $this->state(fn (array $attributes) => [
'view' => 0,
]);
}
}