feat(01-01): add Member notes relationship, morph map, and NoteFactory

- Add notes() morphMany relationship to Member model (ordered by created_at desc)
- Register morph map in AppServiceProvider ('member' => Member::class)
- Create NoteFactory with forMember() and byAuthor() state methods
This commit is contained in:
2026-02-13 12:04:05 +08:00
parent f2912badfa
commit 4ca7530957
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use App\Models\Member;
use App\Models\Note;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class NoteFactory extends Factory
{
protected $model = Note::class;
public function definition(): array
{
return [
'notable_type' => 'member', // Uses morph map alias
'notable_id' => Member::factory(),
'content' => $this->faker->paragraph(),
'author_user_id' => User::factory(),
];
}
/**
* Set the note to belong to a specific member
*/
public function forMember(Member $member): static
{
return $this->state(fn () => [
'notable_type' => 'member',
'notable_id' => $member->id,
]);
}
/**
* Set the note to be authored by a specific user
*/
public function byAuthor(User $user): static
{
return $this->state(fn () => [
'author_user_id' => $user->id,
]);
}
}