2017-03-05 9 views
0

私はPHPサイトを持っています。Laravel 5選択クエリで選択

$getAllTrainings = $db->getAll('SELECT * from add_timetable WHERE active_before >= CURDATE() AND complete = ?i', 0); 

     foreach ($getAllTrainings as $training) { 
      $currentTraining = $db->getOne('SELECT service_id from add_people WHERE service_card = ?s AND training_id = ?s', $service_card, $training['code']); 
      if($currentTraining) { 
        $reg_button = <<<ECHO BUTTON_1 
      } else { 
        $reg_button = <<<ECHO BUTTON_2 
      } 
      echo <<<TRAINING 
     <div class="training__item" id="{$training['code']}" > 
     <h3>{$training['header']}</h3> 
     <p>{$training['description']}</p> 
     <div class="datetime is-flex"> 
      <div class="date"> 
       {$training['date']} 
      </div> 
      <div class="time"> 
       {$training['time']} 
       <div class="small"> 
        {$training['place']} 
       </div> 
      </div> 
     </div> 
     {$reg_button} 
    </div> 
TRAINING; 
     } 

問題はLaravelでそれを行うにはどのようにエコー異なるボタン(クエリによってクエリ)

if($currentTraining) { 
        $reg_button = <<<ECHO BUTTON_1 
      } else { 
        $reg_button = <<<ECHO BUTTON_2 
      } 

です:私はこの問題はここにあるlaravel 5でそれを書き直したいですか?

+0

'<<< ECHO BUTTON_1は何を意味していますか? –

答えて

0

あなたは「トレーニング」(runコマンド:PHP職人メイク:モデルトレーニング)という名前のモデルを作成する必要がまず、その後、あなたのコントローラでモデルをロード(使用のApp \訓練;)、その後、取得するにはコレクションの実行:もちろん

$trainings = Training::where('complete', 1)->whereDate('active_date', '>=', Carbon::now()') 
// note the Carbon usage, you will need to add it by adding use Carbon; 

foreach($trainings as $training){ 
    // do something with your collection here. 
} 

は、あなたは、データベース内のテーブルを持っている必要があり、そしてあなたがテーブルを「トレーニング」にし、それを移行し、移行についての詳細を学ぶ必要がある、その後いけない場合、接続を確立しました。