sendResponse($special_codes, 'Special Codes retrieved successfully.'); } public function show($special_code) : JsonResponse { $special_code = SpecialCode::find($special_code); if (is_null($special_code)) { return $this->sendError('Special Code not found.'); } return $this->sendResponse($special_code, 'Special Code retrieved successfully.'); } public function store(StoreSpecialCodeRequest $request) : JsonResponse { // Validate the request... $validated = $request->validated(); // Store the SpecialCode... if ($validated) { try { $data = SpecialCode::create($validated); return $this->sendResponse($data, 'Special Code created successfully.'); } catch (Exception $e) { return $this->sendError($e->getMessage(), $e->getCode()); } } return $this->sendError('Special Code created failed.', 400); } public function update(UpdateSpecialCodeRequest $request, SpecialCode $special_code) : JsonResponse { // Validate the request... $validated = $request->validated(); // Store the SpecialCode... if ($validated) { try { $data = $special_code->update($validated); return $this->sendResponse($data, 'Special Code updated successfully.'); } catch (Exception $e) { return $this->sendError($e->getMessage(), $e->getCode()); } } return $this->sendError('Special Code created failed.', 400); } public function destroy($id) : JsonResponse { $special_code = SpecialCode::find($id); if (is_null($special_code)) { return $this->sendError('Special Code not found.'); } try { $special_code->delete(); return $this->sendResponse($special_code, 'Special Code deleted successfully.'); } catch (Exception $e) { return $this->sendError($e->getMessage(), $e->getCode()); } } }