43 lines
967 B
PHP
43 lines
967 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Article extends Model
|
|
{
|
|
use HasDateTimeFormatter;
|
|
|
|
protected const CATE_HELP = 1;
|
|
protected const CATE_AGREEMENT = 2;
|
|
protected const CATE_HEALTH = 3;
|
|
|
|
public static $cateMap = [
|
|
'help'=> self::CATE_HELP,
|
|
'agreement'=> self::CATE_AGREEMENT,
|
|
'health'=> self::CATE_HEALTH,
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_show' => 'boolean',
|
|
'is_recommend' => 'boolean',
|
|
];
|
|
|
|
public function hasRead(User $user)
|
|
{
|
|
return ArticlePointsLog::where('user_id', $user->id)->where('article_id', $this->id)->whereDate('created_at', now())->exists();
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(ArticleCategory::class, 'category_id');
|
|
}
|
|
|
|
public function likesInfo()
|
|
{
|
|
return $this->hasMany(ArticleLikesLog::class, 'article_id');
|
|
}
|
|
}
|