belongsTo('App\Object'); } public function floor() { return $this->belongsTo('App\Floor'); } public function status() { return $this->belongsTo('App\Status'); } public function rooms() { return $this->hasMany('App\Room'); } public function getThumbnailAttribute() { return $this->images->count() ? $this->images->first()->thumbnail : 'img/no-photo.png'; } /* public function getSurfaceAttribute() { return $this->rooms->sum('area'); } */ public function getBedroomsAttribute() { $rooms = $this->rooms()->whereIn('room_type_id', [7,8,9,10,11,12])->count(); return trans('global.bedrooms.' . $rooms, ['rooms' => $rooms]); } public function getBathroomsAttribute() { $rooms = $this->rooms()->whereIn('room_type_id', [17,18,19])->count(); return trans('global.bathrooms.' . $rooms, ['rooms' => $rooms]); } }