json([ 'success' => true, 'message' => $message, 'data' => $data, ], $code); } protected function created( mixed $data = null, string $message = 'Resource created successfully' ): JsonResponse { return $this->success($data, $message, Response::HTTP_CREATED); } protected function noContent(): JsonResponse { return response()->json(null, Response::HTTP_NO_CONTENT); } protected function error( string $message = 'Error', int $code = Response::HTTP_BAD_REQUEST, array $errors = [] ): JsonResponse { $response = [ 'success' => false, 'message' => $message, ]; if (! empty($errors)) { $response['errors'] = $errors; } return response()->json($response, $code); } protected function notFound(string $message = 'Resource not found'): JsonResponse { return $this->error($message, Response::HTTP_NOT_FOUND); } protected function unauthorized(string $message = 'Unauthorized'): JsonResponse { return $this->error($message, Response::HTTP_UNAUTHORIZED); } protected function forbidden(string $message = 'Forbidden'): JsonResponse { return $this->error($message, Response::HTTP_FORBIDDEN); } protected function validationError(array $errors, string $message = 'Validation failed'): JsonResponse { return $this->error($message, Response::HTTP_UNPROCESSABLE_ENTITY, $errors); } }