laravel中model类中好用的方法

    public function field()
    {
        return $this->belongsTo(HrmAuthFieldsModel::class, 'filed_id', 'id');
    }

    public function children()
    {
        return $this->hasMany(HrmAuthFuncFieldsModel::class, 'father_id');
    }

    public function getIsEmptyAttribute()
    {
        if (count($this->children) > 0) {
            return false;
        }

        return true;
    }

    public function scopeValid($query)
    {
        $query->where('hrm_auth_func_fields.status', self::STATUS_VALID);
    }

1. 根据属性获取方法

2. getIsEmptyAttirbute()

3. scopeValid()

猜你喜欢

转载自www.cnblogs.com/cjjjj/p/11077419.html