add Post persistence: model, migration, eloquent + fake repo

PostModel maps posts table (id, user_id fk, title, body text,
created_at indexed). EloquentPostRepository: create, find,
findByUserId (desc by created_at), findRecent (limit, desc),
delete - chain via ::query() to keep larastan happy.
FakePostRepository sorts on read (defensive copy each return).
cascade-on-delete on user_id so removing a user nukes their
posts.

phpstan.neon suppresses staticMethod.dynamicCall under
app/*/Eloquent*Repository.php - phpstan-strict-rules flags
Eloquent's fluent builder idiom (Model::query()->orderBy())
because the static methods become instance calls mid-chain.
suppression scoped to repo files only so the rule still
applies elsewhere.
This commit is contained in:
yisroel 2026-05-06 15:22:22 +03:00
parent 73a3acd39f
commit e3dddc60aa
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 261 additions and 0 deletions

View file

@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')
->constrained('users')
->cascadeOnDelete();
$table->string('title');
$table->text('body');
$table->dateTime('created_at')->index();
});
}
public function down(): void
{
Schema::dropIfExists('posts');
}
};