- Add notes migration with polymorphic columns (notable_type, notable_id) - Add foreign key to users table for author tracking - Add indexes on composite (notable_type, notable_id) and created_at - Create Note model with morphTo and belongsTo relationships
37 lines
736 B
PHP
37 lines
736 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class Note extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'notable_type',
|
|
'notable_id',
|
|
'content',
|
|
'author_user_id',
|
|
];
|
|
|
|
/**
|
|
* Get the parent notable model (Member, etc.)
|
|
*/
|
|
public function notable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* Get the user who authored this note
|
|
*/
|
|
public function author(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'author_user_id');
|
|
}
|
|
}
|