<?php
/**
 * Created by PhpStorm.
 * User: zilongs
 * Date: 20-10-5
 * Time: 下午3:37
 */

namespace App\Models;

class Article extends BaseModel
{
    protected $appends = ['is_collect'];
    protected $table = 'articles';
    public static $_post_type = [
        1=>'健康科普',
        2=>'疫苗科普',
        3=>'常见问题'
    ];
    public function getIsCollectAttribute()
    {
        if (!empty(request()->header('token'))) {
                $user = User::getUserByToken();
                if (Collection::where('user_id', $user['id'])->where('article_id', $this->id)->exists()) {
                    return 1;
                }
        }

        return 0;
    }
}
