'json', 'attachments' => 'json', ]; /** * 不参与版本记录的字段 * * @var array|string[] */ protected array $dontVersionable = ['clicks', 'updated_at']; /** * Notes: 阅读记录 * * @Author: 玄尘 * @Date: 2022/10/20 9:57 * @return HasMany */ public function logs(): HasMany { return $this->hasMany(Log::class); } /** * Notes: 阅读 * * @Author: 玄尘 * @Date: 2022/10/20 9:57 * @param int $user_id */ public function read($user_id = '') { $this->incrementClicks(); if ($user_id) { $this->logs()->create([ 'user_id' => $user_id ]); if (Task::query()->shown()->where('key', 'tour_article')->first()) { # todo 阅读得水滴 TaskFacade::do('tour_article', $user_id); } if (Task::query()->shown()->where('key', 'read_article')->first() && $this->categories()->Health()->first()) { # todo 阅读100次得水滴 TaskFacade::do('read_article', $user_id); } } } /** * Notes : 文章所属分类 * * @Date : 2021/4/15 12:44 下午 * @Author : < Jason.C > * @return BelongsToMany */ public function categories(): BelongsToMany { return $this->belongsToMany(Category::class, 'cms_article_category') ->using(ArticleCategory::class) ->withTimestamps(); } /** * Notes : 获取附件的下载地址 * * @Date : 2021/4/16 12:01 下午 * @Author : < Jason.C > * @return Collection */ public function getAttachmentsUrlAttribute(): Collection { return collect($this->attachments)->map(function ($item) { return Storage::url($item); }); } }