2025-07-23 15:41:01 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Boards;
|
|
|
|
|
|
2025-11-06 17:45:49 +09:00
|
|
|
use App\Models\Commons\File;
|
2025-07-23 15:41:01 +09:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-12-28 01:42:47 +09:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2025-07-23 15:41:01 +09:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
2025-08-21 09:50:15 +09:00
|
|
|
/**
|
|
|
|
|
* @mixin IdeHelperPost
|
|
|
|
|
*/
|
2025-07-23 15:41:01 +09:00
|
|
|
class Post extends Model
|
|
|
|
|
{
|
|
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
|
|
protected $table = 'posts';
|
2025-11-06 17:45:49 +09:00
|
|
|
|
2025-07-23 15:41:01 +09:00
|
|
|
protected $fillable = [
|
|
|
|
|
'tenant_id', 'board_id', 'user_id', 'title', 'content', 'editor_type',
|
2025-11-06 17:45:49 +09:00
|
|
|
'ip_address', 'is_notice', 'is_secret', 'views', 'status',
|
2025-07-23 15:41:01 +09:00
|
|
|
];
|
|
|
|
|
|
2025-12-28 01:42:47 +09:00
|
|
|
/**
|
|
|
|
|
* 게시글 첨부파일 (document_type/document_id 기반)
|
|
|
|
|
* - 시스템 게시판의 경우 tenant 무관하게 조회해야 하므로 TenantScope 제외
|
|
|
|
|
*/
|
|
|
|
|
public function files(): HasMany
|
2025-11-06 17:45:49 +09:00
|
|
|
{
|
2025-12-28 01:42:47 +09:00
|
|
|
return $this->hasMany(File::class, 'document_id')
|
|
|
|
|
->where('document_type', 'post')
|
|
|
|
|
->withoutGlobalScope(\App\Models\Scopes\TenantScope::class);
|
2025-07-23 15:41:01 +09:00
|
|
|
}
|
2025-11-06 17:45:49 +09:00
|
|
|
|
|
|
|
|
public function comments()
|
|
|
|
|
{
|
2025-07-23 15:41:01 +09:00
|
|
|
return $this->hasMany(BoardComment::class, 'post_id')->whereNull('parent_id')->where('status', 'active');
|
|
|
|
|
}
|
2025-11-06 17:45:49 +09:00
|
|
|
|
|
|
|
|
public function board()
|
|
|
|
|
{
|
2025-07-23 15:41:01 +09:00
|
|
|
return $this->belongsTo(Board::class, 'board_id');
|
|
|
|
|
}
|
|
|
|
|
}
|