6
0
Fork 0

添加文章详情今日是否阅读

release
vine_liutk 2021-12-14 17:41:40 +08:00
parent f834f8f53b
commit 719e74876c
2 changed files with 6 additions and 0 deletions

View File

@ -23,6 +23,7 @@ class ArticleResource extends JsonResource
'points'=> $this->points,
'likes' => $this->likes,
'like_status' => $this->whenLoaded('likesInfo', $this->likesInfo->count() > 0),
'has_read' => $this->hasRead($request->user()),
'media_type'=> $this->media_type,
'media_content'=> json_decode($this->media_content, true),
'created_at' => $this->created_at->toDateTimeString(),

View File

@ -25,6 +25,11 @@ class Article extends Model
'is_recommend' => 'boolean',
];
public function hasRead(User $user)
{
return ArticleLikesLog::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');