Cast track number as int

This commit is contained in:
An Phan 2016-03-28 21:18:09 +08:00
parent f4e5a4501d
commit 8142782766

View file

@ -30,6 +30,7 @@ class Song extends Model
protected $casts = [ protected $casts = [
'length' => 'float', 'length' => 'float',
'mtime' => 'int', 'mtime' => 'int',
'track' => 'int',
]; ];
/** /**
@ -133,12 +134,11 @@ class Song extends Model
continue; continue;
} }
// If we're updating only one song, take into account the title and lyrics // If we're updating only one song, take into account the title, lyrics, and track number.
// and track number.
if (count($ids) === 1) { if (count($ids) === 1) {
$song->title = trim($data['title']) ?: $song->title; $song->title = trim($data['title']) ?: $song->title;
$song->lyrics = trim($data['lyrics']); $song->lyrics = trim($data['lyrics']);
$song->track = trim($data['track']); $song->track = (int) trim($data['track']);
} }
// If "newArtist" is provided, we'll see if such an artist name is found in our database. // If "newArtist" is provided, we'll see if such an artist name is found in our database.