Laravel Eloquent Group日期

时间:2014-07-01 02:58:59

标签: laravel eloquent

我试图搜索我如何在我的laravel下面的这张图片上创建相同的结果。我试图按日期分组。同一个月的所有日期将合并为一行。 enter image description here

到目前为止我完成了什么。我无法合并具有相同月份的日期。 有谁知道我怎么能做到这一点?感谢 enter image description here

1 个答案:

答案 0 :(得分:0)

<table>
    <thead>
        <tr>
            <th>Test Type</th>
            <?php
                $types = Tblreporttype::all();
            ?>
            @foreach($types as $type)
                <?php  
                    $dates = Tblreportdate::with('tblreporttype')
                        ->groupBy('fDate')
                        ->where('tblreporttype_id', '=', $type->id)
                        ->get();
                ?>
                @foreach($dates as $date)
                <?php
                    $convert = $date->fDate;
                    $my_date = date('M/y', strtotime($convert));
                ?>
                    <th width="100">
                        <?php
                            if($my_date == $my_date) {
                                echo $my_date;
                            }
                        ?>
                    </th>
                @endforeach
            @endforeach
        </tr>
    </thead>
    <tbody>
            <?php  
                $dates = Tblreportdate::with('tblreporttype')
                ->groupBy('fDate')
                ->get();
            ?>
            <?php
                $types = Tblreporttype::all();
            ?>
                    @foreach($types as $type)
        <tr>
                        <td width="200">{{ $type->fType }}</td>
                    @foreach($dates as $date)
                    <?php
                        $convert = $date->fDate;
                        $my_date = date('d', strtotime($convert));
                    ?>
                    <td width="100">
                        <?php
                            if($date->tblreporttype->id == $type->id) {
                                echo $my_date; 
                            } else {
                            echo " ";
                            }
                        ?>
                    </td>
                @endforeach
        </tr>
            @endforeach
    </tbody>

</table>

这是输出enter image description here

相关问题