72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class GcBoard extends Model
|
|
{
|
|
protected $table = 'gc_board';
|
|
protected $primaryKey = 'seq';
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
'gubun', 'subject', 'content', 'admin_num', 'regdate',
|
|
'hiding', 'first_sign', 'link_01', 'link_02', 'file_01', 'file_02', 'hit',
|
|
];
|
|
|
|
protected $casts = [
|
|
'seq' => 'integer',
|
|
'admin_num' => 'integer',
|
|
'first_sign' => 'integer',
|
|
'hit' => 'integer',
|
|
];
|
|
|
|
/** 노출 + 공지 */
|
|
public function scopeVisibleNotice($q)
|
|
{
|
|
return $q->where('gubun', 'notice')->where('hiding', 'N');
|
|
}
|
|
|
|
/** 우선노출/최신순 정렬 */
|
|
public function scopeNoticeOrder($q)
|
|
{
|
|
return $q->orderByDesc('first_sign')
|
|
->orderByDesc('regdate')
|
|
->orderByDesc('seq');
|
|
}
|
|
|
|
/** regdate가 0000-00-00... 일 수 있어 안전 파싱 */
|
|
public function regdateCarbon(): ?Carbon
|
|
{
|
|
$v = $this->regdate;
|
|
if (!$v || $v === '0000-00-00 00:00:00') return null;
|
|
|
|
try {
|
|
return Carbon::parse($v);
|
|
} catch (\Throwable $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** 리스트 태그(임시 규칙): 우선노출이면 공지, 아니면 안내 */
|
|
public function uiTag(): array
|
|
{
|
|
if ((int)$this->first_sign > 0) {
|
|
return ['label' => '공지', 'class' => 'n2-tag'];
|
|
}
|
|
return ['label' => '안내', 'class' => 'n2-tag n2-tag--info'];
|
|
}
|
|
|
|
/** 링크 안전 보정 */
|
|
public function safeLink(?string $url): ?string
|
|
{
|
|
$url = trim((string)$url);
|
|
if ($url === '') return null;
|
|
|
|
// http(s) 아니면 그냥 반환(내부경로일 수도 있으니)
|
|
return $url;
|
|
}
|
|
}
|