BlogController was an empty stub with no view, so /blog 500'd on every visit. Adds a real Post model, public listing/detail pages, and an admin CRUD screen mirroring the existing Exercise admin pattern (image upload or URL, auto-slug, publish toggle). Seeds 5 real posts so it's not empty on launch. Also fixes two things that were silently broken: phpunit.xml pointed DB_DATABASE at a non-existent "testing" file with no DB_CONNECTION set, and the stock ExampleTest had RefreshDatabase commented out - both meant the test suite never actually ran successfully. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
36 lines
991 B
PHP
36 lines
991 B
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
|
|
*/
|
|
class PostFactory extends Factory
|
|
{
|
|
public function definition(): array
|
|
{
|
|
$title = rtrim(fake()->sentence(rand(4, 8)), '.');
|
|
|
|
return [
|
|
'title' => $title,
|
|
'slug' => Str::slug($title) . '-' . fake()->unique()->numberBetween(1, 100000),
|
|
'excerpt' => fake()->sentence(rand(15, 25)),
|
|
'body' => implode("\n\n", fake()->paragraphs(rand(4, 7))),
|
|
'cover_image' => null,
|
|
'author_id' => User::query()->inRandomOrder()->value('id'),
|
|
'published_at' => now()->subDays(fake()->numberBetween(0, 60)),
|
|
];
|
|
}
|
|
|
|
public function draft(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'published_at' => null,
|
|
]);
|
|
}
|
|
}
|