. */ namespace Poniverse\Ponyfm\Commands; use Gate; use Poniverse\Ponyfm\Models\Album; use Auth; class DeleteAlbumCommand extends CommandBase { /** @var int */ private $_albumId; /** @var Album */ private $_album; public function __construct($albumId) { $this->_albumId = $albumId; $this->_album = Album::find($albumId); } /** * @return bool */ public function authorize() { return Gate::allows('delete', $this->_album); } /** * @throws \Exception * @return CommandResponse */ public function execute() { foreach ($this->_album->tracks as $track) { $track->album_id = null; $track->track_number = null; $track->updateTags(); $track->save(); } $this->_album->delete(); return CommandResponse::succeed(); } }