<?php

namespace App\Models;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @description 评论管理
 * @author  system;
 * @version    1.0
 * @date 2018-05-14 10:49:40
 *
 */
class AlbumCommentsModel extends BaseModel
{
    use SoftDeletes;
    protected $dates = ['delete_at'];
    /**
     * 数据表名
     *
     * @var string
     *
     */
    protected $table = 'album_comments';
    /**
     * 主键
     */
    protected $primaryKey = 'id';

    //分页
    protected $perPage = PAGE_NUMS;

    /**
     * 可以被集体附值的表的字段
     *
     * @var string
     */
    protected $fillable = [
        'store_id',
        'user_id',
        'comments_id',
        'content',
        'sys_reply',
        'news_id',
    ];

    public function user()
    {
        return $this->belongsTo('App\Models\AlbumUserModel', 'user_id');
    }

    public function username(){
        return (new AlbumUserModel())->find($this->user_id)?(new AlbumUserModel())->find($this->user_id)->username:$this->user_id;
    }

    public function replys(){
        return $this->hasMany('App\Models\AlbumCommentsModel','comments_id','id');
    }

}