Files
sam-api/app/Models/Boards/Post.php

45 lines
1.1 KiB
PHP
Raw Normal View History

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