Files
landing-api/database/factories/ProjectFactory.php
Josep Piguillem 3897113313 Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer
collective, backed by the Pireon OAuth identity server. The public site is a
separate, server-rendered application consuming /api/public/v1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 17:55:27 +02:00

94 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Enums\ProjectStatus;
use App\Models\Project;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends Factory<Project>
*/
class ProjectFactory extends Factory
{
protected $model = Project::class;
/**
* @return array<string, mixed>
*/
public function definition(): array
{
$title = rtrim(fake()->unique()->catchPhrase(), '.');
$status = fake()->randomElement(ProjectStatus::cases());
return [
'title' => $this->eachLocale(fn (string $l) => "{$title} ({$l})"),
'slug' => $this->eachLocale(fn (string $l) => Str::slug("{$title}-{$l}")),
'tagline' => $this->eachLocale(fn () => fake()->sentence(8)),
'description' => $this->eachLocale(fn () => '<p>'.implode('</p><p>', fake()->paragraphs(3)).'</p>'),
'decisions' => $this->eachLocale(fn () => '<p>'.fake()->paragraph().'</p>'),
'postmortem' => null,
'meta_title' => $this->eachLocale(fn () => Str::limit($title, 55, '')),
'meta_description' => $this->eachLocale(fn () => fake()->sentence(14)),
'status' => $status,
'demo_url' => fake()->optional()->url(),
'is_featured' => fake()->boolean(20),
'needs_help' => fake()->boolean(30),
'started_at' => fake()->dateTimeBetween('-3 years'),
'published_at' => now()->subDays(fake()->numberBetween(1, 400)),
'position' => fake()->numberBetween(0, 20),
];
}
public function published(): static
{
return $this->state(fn () => ['published_at' => now()->subDay()]);
}
public function draft(): static
{
return $this->state(fn () => ['published_at' => null]);
}
public function active(): static
{
return $this->state(fn () => ['status' => ProjectStatus::Active]);
}
public function needingHelp(): static
{
return $this->state(fn () => [
'needs_help' => true,
'status' => ProjectStatus::Active,
]);
}
/**
* A finished project with the write-up that makes it worth reading — the
* kind of content a commercial consultancy cannot publish.
*/
public function withPostmortem(): static
{
return $this->state(fn () => [
'status' => ProjectStatus::Archived,
'ended_at' => fake()->dateTimeBetween('-1 year'),
'postmortem' => $this->eachLocale(
fn () => '<p>'.implode('</p><p>', fake()->paragraphs(2)).'</p>',
),
]);
}
/** @return array<string, string> */
protected function eachLocale(callable $value): array
{
return collect(array_keys(config('locales.supported')))
->mapWithKeys(fn (string $l) => [$l => $value($l)])
->all();
}
}