hasMany(Document::class); } public function isComeIn(){ return $this->id == self::DEN; } public function isComeOut(){ return $this->id == self::DI; } public function isPrivate(){ return $this->id == self::NOIBO; } public function getUnreadAttribute(){ return $this->documents() ->wherehas('receivers', function($query) { return $query->where('id', auth()->id())->where('seen', false); })->count(); } public function getCountAttribute(){ return $this->documents() ->wherehas('receivers', function($query) { return $query->where('id', auth()->id()); })->count(); } }