2017-10-03 6 views
-1

コントローラにスイッチケースがあり、エラーの変数をテキストに変換して、私のajaxコールに戻したいと思います。私のエラーメッセージをajax呼び出しに戻す方法は?あなたはifを使用する必要がありますコントローラからajaxコールへのエラーの返信

switch (true) { 
     case (($to <= $from) && ($statistics > $from)): 
      $error = [trans('report.errors.combine')]; 
      return $error; 
      break; 
     case ($to <= $from): 
      $error = [trans('report.errors.to_date')]; 
      return $error; 
      break; 
     case ($statistics > $from): 
      $error = [trans('report.errors.statistics')]; 
      return $error; 
      break; 
     default: 
      $this->generate($request); 
    } 
+1

ので、あなたの質問は何ですか? – parpar

答えて

1

、この代わりにswitch caseためelse if & else条件。 AJAXの応答を

if(($to <= $from) && ($statistics > $from)){ 
     $error = [trans('report.errors.combine')]; 
    } 
    elseif($to <= $from){ 
     $error = [trans('report.errors.to_date')]; 
    } 
    elseif($to <= $from){ 
     $error = [trans('report.errors.statistics')]; 
    } 
    elseif($statistics > $from){ 
     $error = [trans('report.errors.statistics')]; 
    } 
    else{ 
     $content = $this->generate($request); 
    } 

$res = (isset($error)) ? $error : $content; 

header('Content-Type: application/json'); 
echo json_encode($res); exit(); 
関連する問題