添加文章详情今日是否阅读
parent
f834f8f53b
commit
719e74876c
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue