2017-03-05 90 views
0

我有一個php網站。我想重寫它laravel 5.問題是在這裏: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; 
     } 

問題是回聲不同的按鈕(通過查詢查詢)

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

如何做到在Laravel?

+0

'<<< ECHO BUTTON_1'的意思是什麼? –

回答

0

首先,你需要創建一個名爲模式「培訓」 (運行命令: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. 
} 

當然,你需要有表在你的數據庫,並建立連接,如果你不那麼你需要了解更多關於遷移,使表「培訓」,並進行遷移。