Php Laravel 5在选择查询中选择

Php Laravel 5在选择查询中选择,php,mysql,laravel,laravel-5,laravel-5.2,Php,Mysql,Laravel,Laravel 5,Laravel 5.2,我有一个php网站。我想把它改写成拉威尔5。问题在于: $getAllTrainings = $db->getAll('SELECT * from add_timetable WHERE active_before >= CURDATE() AND complete = ?i', 0); foreach ($getAllTrainings as $training) { $currentTraining = $db->getOn

我有一个php网站。我想把它改写成拉威尔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;
        }
$getAllTrainings=$db->getAll('SELECT*from add_timeline,其中活动时间在>=CURDATE()之前,完成时间为?'i',0);
foreach($getAllTrainings作为$training){
$currentTraining=$db->getOne('从添加人员中选择服务id,其中服务卡=?s和培训id=?s',$service卡,$training['code']);
如果($currentTraining){

$reg_button=首先需要创建名为“Training”的模型(运行命令:php artisan make:model Training),然后在控制器中加载模型(使用App\Training;),然后运行集合:

$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.
}
当然,您需要在数据库中拥有该表,并建立连接,如果没有,则需要了解有关迁移的更多信息,制作一个表“Trainings”并进行迁移。

什么是

$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.
}