72 lines
1.6 KiB
PHP
72 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Boards;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 게시글 댓글 모델
|
|
*
|
|
* @property int $id
|
|
* @property int $post_id
|
|
* @property int|null $tenant_id
|
|
* @property int $user_id
|
|
* @property int|null $parent_id
|
|
* @property string $content
|
|
* @property string|null $ip_address
|
|
* @property string $status
|
|
*/
|
|
class BoardComment extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'board_comments';
|
|
|
|
protected $fillable = [
|
|
'post_id',
|
|
'tenant_id',
|
|
'user_id',
|
|
'parent_id',
|
|
'content',
|
|
'ip_address',
|
|
'status',
|
|
];
|
|
|
|
// =========================================================================
|
|
// Relationships
|
|
// =========================================================================
|
|
|
|
public function post(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Post::class, 'post_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BoardComment::class, 'parent_id');
|
|
}
|
|
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(BoardComment::class, 'parent_id')
|
|
->where('status', 'active');
|
|
}
|
|
|
|
/**
|
|
* Alias for children() - used for eager loading
|
|
*/
|
|
public function replies(): HasMany
|
|
{
|
|
return $this->children();
|
|
}
|
|
}
|