From a57c1640e876069f944faba471bb5c5b976f3bb8 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Mon, 11 Jul 2016 21:07:45 +0100 Subject: [PATCH] #86: Fixed editing albums with more than 1 track --- app/Commands/EditAlbumCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Commands/EditAlbumCommand.php b/app/Commands/EditAlbumCommand.php index 2f7fe285..42bbcfe0 100644 --- a/app/Commands/EditAlbumCommand.php +++ b/app/Commands/EditAlbumCommand.php @@ -63,7 +63,6 @@ class EditAlbumCommand extends CommandBase 'title' => 'required|min:3|max:50', 'cover' => 'image|mimes:png|min_width:350|min_height:350', 'cover_id' => 'exists:images,id', - 'track_ids' => 'exists:tracks,id', 'username' => 'exists:users,username' ]; @@ -73,6 +72,14 @@ class EditAlbumCommand extends CommandBase return CommandResponse::fail($validator); } + $trackIds = explode(',', $this->_input['track_ids']); + $trackIdsCount = count($trackIds); + $trackDbCount = DB::table('tracks')->whereIn('id', $trackIds)->count(); + + if ($trackDbCount != $trackIdsCount) { + return CommandResponse::fail("Track IDs invalid"); + } + $this->_album->title = $this->_input['title']; $this->_album->description = $this->_input['description'];