/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $deleteArray = explode(',', $id); if (count($deleteArray) == 0) { return $this->respondBadRequest('No snippet was selected to be deleted. Please select the snippets you want to delete by clicking on the checkboxes next to them'); } if (count($deleteArray) > 50) { return $this->respondBadRequest('You are not allowed to delete more than 50 snippets at one time'); } try { $messages = []; $resourceList = Snippet::whereIn('id', $deleteArray); $deletedCount = $resourceList->delete(); $messages['success'][] = $deletedCount . ' Snippet' . strtolower($deletedCount == 1 ? '' : 's') . ' deleted successfully.'; return $this->respondWithMessages($messages); } catch (Exception $e) { \Log::error($e->getTraceAsString()); return $this->respondInternalError($e->getMessage()); } }