1 | <?php |
||
28 | class Song extends Model |
||
29 | { |
||
30 | use SupportsDeleteWhereIDsNotIn; |
||
31 | |||
32 | protected $guarded = []; |
||
33 | |||
34 | /** |
||
35 | * Attributes to be hidden from JSON outputs. |
||
36 | * Here we specify to hide lyrics as well to save some bandwidth (actually, lots of it). |
||
37 | * Lyrics can then be queried on demand. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $hidden = ['lyrics', 'updated_at', 'path', 'mtime']; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $casts = [ |
||
47 | 'length' => 'float', |
||
48 | 'mtime' => 'int', |
||
49 | 'track' => 'int', |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Indicates if the IDs are auto-incrementing. |
||
54 | * |
||
55 | * @var bool |
||
56 | */ |
||
57 | public $incrementing = false; |
||
58 | |||
59 | public function artist() |
||
63 | |||
64 | public function album() |
||
68 | |||
69 | public function playlists() |
||
73 | |||
74 | /** |
||
75 | * Scrobble the song using Last.fm service. |
||
76 | * |
||
77 | * @param User $user |
||
78 | * @param string $timestamp The UNIX timestamp in which the song started playing. |
||
79 | * |
||
80 | * @return mixed |
||
81 | */ |
||
82 | public function scrobble(User $user, $timestamp) |
||
102 | |||
103 | /** |
||
104 | * Get a Song record using its path. |
||
105 | * |
||
106 | * @param string $path |
||
107 | * |
||
108 | * @return Song|null |
||
109 | */ |
||
110 | public static function byPath($path) |
||
114 | |||
115 | /** |
||
116 | * Update song info. |
||
117 | * |
||
118 | * @param array $ids |
||
119 | * @param array $data The data array, with these supported fields: |
||
120 | * - title |
||
121 | * - artistName |
||
122 | * - albumName |
||
123 | * - lyrics |
||
124 | * All of these are optional, in which case the info will not be changed |
||
125 | * (except for lyrics, which will be emptied). |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public static function updateInfo($ids, $data) |
||
168 | |||
169 | /** |
||
170 | * Update a single song's info. |
||
171 | * |
||
172 | * @param string $title |
||
173 | * @param string $albumName |
||
174 | * @param string $artistName |
||
175 | * @param string $lyrics |
||
176 | * @param int $track |
||
177 | * @param int $compilationState |
||
178 | * |
||
179 | * @return self |
||
180 | */ |
||
181 | public function updateSingle($title, $albumName, $artistName, $lyrics, $track, $compilationState) |
||
222 | |||
223 | /** |
||
224 | * Scope a query to only include songs in a given directory. |
||
225 | * |
||
226 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
227 | * @param string $path Full path of the directory |
||
228 | * |
||
229 | * @return \Illuminate\Database\Eloquent\Builder |
||
230 | */ |
||
231 | public function scopeInDirectory($query, $path) |
||
238 | |||
239 | /** |
||
240 | * Get all songs favored by a user. |
||
241 | * |
||
242 | * @param User $user |
||
243 | * @param bool $toArray |
||
244 | * |
||
245 | * @return \Illuminate\Database\Eloquent\Collection|array |
||
246 | */ |
||
247 | public static function getFavorites(User $user, $toArray = false) |
||
256 | |||
257 | /** |
||
258 | * Get the song's Object Storage url for streaming or downloading. |
||
259 | * |
||
260 | * @param AwsClient $s3 |
||
261 | * |
||
262 | * @return string |
||
263 | */ |
||
264 | public function getObjectStoragePublicUrl(AwsClient $s3 = null) |
||
289 | |||
290 | /** |
||
291 | * Get the YouTube videos related to this song. |
||
292 | * |
||
293 | * @param string $youTubePageToken The YouTube page token, for pagination purpose. |
||
294 | * |
||
295 | * @return @return object|false |
||
296 | */ |
||
297 | public function getRelatedYouTubeVideos($youTubePageToken = '') |
||
301 | |||
302 | /** |
||
303 | * Get Lyrics related to this song. |
||
304 | * |
||
305 | * @return object|false |
||
306 | */ |
||
307 | public function getSongLyrics() |
||
311 | |||
312 | /** |
||
313 | * Sometimes the tags extracted from getID3 are HTML entity encoded. |
||
314 | * This makes sure they are always sane. |
||
315 | * |
||
316 | * @param $value |
||
317 | */ |
||
318 | public function setTitleAttribute($value) |
||
322 | |||
323 | /** |
||
324 | * Some songs don't have a title. |
||
325 | * Fall back to the file name (without extension) for such. |
||
326 | * |
||
327 | * @param $value |
||
328 | * |
||
329 | * @return string |
||
330 | */ |
||
331 | public function getTitleAttribute($value) |
||
335 | |||
336 | /** |
||
337 | * Prepare the lyrics for displaying. |
||
338 | * |
||
339 | * @param $value |
||
340 | * |
||
341 | * @return string |
||
342 | */ |
||
343 | public function getLyricsAttribute($value) |
||
350 | |||
351 | /** |
||
352 | * Determine if the song has lyrics. |
||
353 | * |
||
354 | * @return bool |
||
355 | */ |
||
356 | public function hasLyrics() |
||
360 | |||
361 | /** |
||
362 | * Determine if the song is an AWS S3 Object. |
||
363 | * |
||
364 | * @return bool |
||
365 | */ |
||
366 | public function isS3ObjectAttribute() |
||
370 | |||
371 | /** |
||
372 | * Get the bucket and key name of an S3 object. |
||
373 | * |
||
374 | * @return bool|array |
||
375 | */ |
||
376 | public function getS3ParamsAttribute() |
||
386 | } |
||
387 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: