like()->where('user_id',Auth::user()->id)->get()->isNotEmpty(); } function getLikesAttribute(){ return $this->like()->count(); } public function getAttachmentsImageAttribute() { if($this->attachments()){ return $this->attachments() ->whereIn('mime',['png','jpeg','jpg']) ->orderBy('id','desc') ->get(); }else{ return []; } } public function getAttachmentsVideoAttribute() { if($this->attachments()){ return $this->attachments()->where('mime','mp4')->orderBy('id','desc')->get(); }else{ return []; } } public function getShopAttribute() { if($this->shop_id!=null){ if($this->shop()){ return $this->shop()->first(); }else{ return null; } }else{ return null; } } public function getUserAttribute() { return $this->user()->first(); } public function getcategoryAttribute() { return $this->category()->first(); } public function user() { return $this->belongsTo(User::class, 'user_id'); } public function shop() { return $this->belongsTo(Shop::class, 'shop_id'); } public function category() { return $this->belongsTo(Category::class, 'category_id'); } public function offers() { return $this->hasMany(Offer::class, 'adv_id'); } public function attachments() { return $this->morphMany(Attachment::class, 'attachmentable'); } public function experience() { return $this->morphMany(Experience::class, 'experiencable'); } public function comments() { return $this->morphMany(Comment::class,'commentable'); } function like() { return $this->morphMany(Like::class,'likable'); } public function City() { return $this->belongsTo(City::class,'city_id'); } }