- BoardComment 모델에 replies() 관계 추가 (children 별칭)
- PostService 댓글 CRUD에 user eager loading 추가
- getComments(): with(['user', 'replies.user'])
- createComment(): $comment->load('user')
- updateComment(): $comment->fresh('user')
- 댓글 작성자 이름 정상 표시
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
50 lines
1016 B
PHP
50 lines
1016 B
PHP
<?php
|
|
|
|
namespace App\Models\Boards;
|
|
|
|
use App\Models\Members\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @mixin IdeHelperBoardComment
|
|
*/
|
|
class BoardComment extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'board_comments';
|
|
|
|
protected $fillable = [
|
|
'post_id', 'tenant_id', 'user_id', 'parent_id', 'content', 'ip_address', 'status',
|
|
];
|
|
|
|
public function post()
|
|
{
|
|
return $this->belongsTo(Post::class, 'post_id');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(BoardComment::class, 'parent_id');
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(BoardComment::class, 'parent_id')->where('status', 'active');
|
|
}
|
|
|
|
/**
|
|
* Alias for children() - used by PostService eager loading
|
|
*/
|
|
public function replies()
|
|
{
|
|
return $this->children();
|
|
}
|
|
}
|