#4 conflict resolve
This commit is contained in:
43
database/factories/PostFactory.php
Normal file
43
database/factories/PostFactory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\PostStatus;
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<Post>
|
||||
*/
|
||||
class PostFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$title = fake()->sentence(6, false);
|
||||
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'title' => $title,
|
||||
'content' => fake()->paragraphs(3, true),
|
||||
'slug' => Str::slug($title).'-'.fake()->unique()->randomNumber(4),
|
||||
'status' => fake()->randomElement(PostStatus::cases()),
|
||||
];
|
||||
}
|
||||
|
||||
public function published(): static
|
||||
{
|
||||
return $this->state(['status' => PostStatus::Published]);
|
||||
}
|
||||
|
||||
public function draft(): static
|
||||
{
|
||||
return $this->state(['status' => PostStatus::Draft]);
|
||||
}
|
||||
}
|
||||
34
database/migrations/2026_05_12_022449_create_posts_table.php
Normal file
34
database/migrations/2026_05_12_022449_create_posts_table.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('posts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->longText('content');
|
||||
$table->string('slug')->unique();
|
||||
$table->string('status')->default('draft');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['user_id', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('posts');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user