/** * Display a listing of the resource. * * @return Response */ public function index() { try { $statusCode = 200; // $response = [ // 'Age List' => [] // ]; $ages = Age::all(); foreach ($ages as $age) { // $response['Age List'][] = ['id' => $age->id, 'Age' => $age->age]; } // $response=$gender; } catch (Exception $e) { $statusCode = 400; } finally { return Response::json($response, $statusCode); } }