You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use App\Casts\EncryptFixed;
use Carbon\Carbon;
class BoardArticle extends BaseSoftDeleteModel
{
protected $table = 'board_article';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'board_id', 'uid',
'notice', 'image', 'category',
'name', 'email', 'phone', 'zone',
'subject', 'content', 'related_link',
'view_count',
'created_id', 'created_at'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
];
protected $visible = [
'id', 'board_id', 'uid',
'notice', 'image', 'category',
'name', 'email', 'phone', 'zone',
'subject', 'content', 'related_link',
'view_count',
'created_id', 'created_at',
'is_new',
'assets', 'assets_count',
'comments', 'comments_count'
];
protected $appends = [
'is_new'
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
];
public function getIsNewAttribute()
{
if ($this->created_at) {
return $this->created_at->diffInHours(Carbon::now()) <= 24;
}
return false;
}
public function board()
{
return $this->belongsTo('App\Models\Board', 'board_id');
}
public function asset()
{
return $this->belongsTo('App\Models\Asset', 'image', 'uid');
}
public function assets()
{
return $this->hasMany('App\Models\BoardAsset', 'article_id');
}
public function comments()
{
return $this->hasMany('App\Models\BoardComment', 'article_id');
}
public function user()
{
return $this->belongsTo('App\Models\User', 'created_id');
}
}