url_alias = preg_replace('/[^a-z0-9\-]/', '-', strtolower($this->name)); } public function photoCount() { return $this->photos()->whereIn('album_id', DbHelper::getAlbumIDsForCurrentUser())->count(); } public function photos() { return $this->belongsToMany(Photo::class, 'photo_labels'); } public function thumbnailUrl($thumbnailName) { $photo = $this->photos() ->whereIn('album_id', DbHelper::getAlbumIDsForCurrentUser()) ->inRandomOrder() ->first(); if (!is_null($photo)) { return $photo->album->getAlbumSource()->getUrlToPhoto($photo, $thumbnailName); } // Rotate standard images $images = [ asset('themes/base/images/empty-album-1.jpg'), asset('themes/base/images/empty-album-2.jpg'), asset('themes/base/images/empty-album-3.jpg') ]; return $images[rand(0, count($images) - 1)]; } public function url() { return route('viewLabel', $this->url_alias); } }