Как генерировать динамические столбцы таблицы при просмотре - PullRequest
0 голосов
/ 29 января 2019

Мне нужно создать таблицу такого типа из таблицы базы данных.enter image description here

это выходная коллекция из моего запроса

[{delivery_date: "2019-01-09", delivery_count: "5", price: "190.00", total_price: "950.00"}
{delivery_date: "2019-01-10", delivery_count: "45", price: "170.00", total_price: "7650.00"}
{delivery_date: "2019-01-10", delivery_count: "2", price: "50.00", total_price: "100.00"}
{delivery_date: "2019-01-10", delivery_count: "3", price: "60.00", total_price: "180.00"}
{delivery_date: "2019-01-10", delivery_count: "3", price: "185.00", total_price: "555.00"}
{delivery_date: "2019-01-16", delivery_count: "6", price: "50.00", total_price: "300.00"}]

, и именно так я запрашиваю таблицу

 $deliveries = DB::table('deliveries')
    ->where('user_id',Auth::id())
    ->groupBy('price','delivery_date')
    ->orderBy('delivery_date')
    ->select('delivery_date',DB::raw('SUM(number) as delivery_count'),'price', DB::raw('SUM(number*price) as total_price'))
    ->get();

ивот как я отображаю данные

<table class="display table table-condensed table-bordered">
    <thead>
         <th>Date</th>
         @foreach($deliveries as $delivery)
             <th>{{$delivery->price}}</th>
         @endforeach
    </thead>
    <tbody>

         @foreach($deliveries as $delivery) 
              <tr>      
                  <td>{{ $delivery->delivery_date }}</td>   
                   @if($delivery->price = $deliveries[$i]->price)
                        <td>{{ $delivery->delivery_count }}</td>   
                   @else
                        <td>0</td>   
                   @endif                        
              </tr>
         @endforeach

     </tbody>
 </table>

вот что я получаю с моего взгляда

enter image description here

Я застрял здесь иВсе еще пытаюсь понять, как это сделать .. Пожалуйста, помогите.Спасибо, ребята!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...