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:
parent
73a3acd39f
commit
e3dddc60aa
5 changed files with 261 additions and 0 deletions
40
backend/app/Post/PostModel.php
Normal file
40
backend/app/Post/PostModel.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Post;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $title
|
||||
* @property string $body
|
||||
* @property Carbon $created_at
|
||||
*
|
||||
* @method static Builder<static>|PostModel newModelQuery()
|
||||
* @method static Builder<static>|PostModel newQuery()
|
||||
* @method static Builder<static>|PostModel query()
|
||||
* @method static Builder<static>|PostModel whereId($value)
|
||||
* @method static Builder<static>|PostModel whereUserId($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class PostModel extends Model
|
||||
{
|
||||
protected $table = 'posts';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'title',
|
||||
'body',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue