the browser-facing portion of osu!
at master 2.0 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Models; 7 8use App\Traits\Memoizes; 9 10/** 11 * @property \Illuminate\Database\Eloquent\Collection $albums ArtistAlbum 12 * @property string|null $bandcamp 13 * @property \Illuminate\Database\Eloquent\Collection $beatmapsets Beatmapset 14 * @property string|null $cover_url 15 * @property \Carbon\Carbon|null $created_at 16 * @property string $description 17 * @property string|null $facebook 18 * @property string|null $header_url 19 * @property int $id 20 * @property Label $label 21 * @property int|null $label_id 22 * @property string $name 23 * @property string|null $patreon 24 * @property string|null $soundcloud 25 * @property string|null $spotify 26 * @property \Illuminate\Database\Eloquent\Collection $tracks ArtistTrack 27 * @property string|null $twitter 28 * @property \Carbon\Carbon|null $updated_at 29 * @property int|null $user_id 30 * @property string|null $video_url 31 * @property int $visible 32 * @property string|null $website 33 * @property string|null $youtube 34 */ 35class Artist extends Model 36{ 37 use Memoizes; 38 39 protected $casts = [ 40 'visible' => 'boolean', 41 ]; 42 43 public function label() 44 { 45 return $this->belongsTo(Label::class); 46 } 47 48 public function albums() 49 { 50 return $this->hasMany(ArtistAlbum::class); 51 } 52 53 public function beatmapsets() 54 { 55 return $this->hasManyThrough(Beatmapset::class, ArtistTrack::class, null, 'track_id'); 56 } 57 58 public function tracks() 59 { 60 return $this->hasMany(ArtistTrack::class); 61 } 62 63 /** 64 * This requires querying the model with `->withMax('tracks', 'created_at')`. 65 */ 66 public function hasNewTracks() 67 { 68 $date = parse_time_to_carbon($this->attributes['tracks_max_created_at']); 69 70 return $date !== null && $date->addMonths(1)->isFuture(); 71 } 72 73 public function url() 74 { 75 return route('artists.show', $this); 76 } 77}