user_id)) { $model->user_id = get_current_user_id(); } if (empty($model->object_type)) { $model->object_type = 'feed'; } if (empty($model->type)) { $model->type = 'like'; } }); } public function scopeTypeBy($query, $type = 'like') { if ($type) { $query->where('type', $type); } return $query; } public function scopeObjectType($query, $type = 'feed') { if ($type) { $query->where('object_type', $type); } return $query; } public function user() { return $this->belongsTo(User::class, 'user_id', 'ID'); } public function xprofile() { return $this->belongsTo(XProfile::class, 'user_id', 'user_id'); } public function feed() { return $this->belongsTo(Feed::class, 'object_id', 'id') ->where('object_type', 'feed'); } public function comment() { return $this->belongsTo(Comment::class, 'object_id', 'id') ->where('object_type', 'comment'); } }