查询然后在Laravel 5.5中查看?

时间:2018-11-27 06:19:55

标签: php laravel

希望您可以在这里帮助我解决我的问题。我想做的是,当您输入供应商时,它会自动转到视图中的表,您可以输入无限数量的供应商,但是在视图(表视图)中,您需要将其限制为3。为了做到这一点,我一直试图循环列和行,但它重复了我输入的供应商。价格而不是填充每个项目指定的行,而是向右斜排。我的循环有问题,但是我似乎不知道这是什么。我在数据库中有不同的项目,供应商和价格表。希望你能帮助我。我用语言不能很好地表达这个问题。但是我有支持图片附在这篇文章上。使用Laravel 5.5

您在其中输入供应商详细信息的模式

Modal where you enter supplier details

查看供应商,价格和项目的表

Table where you view supplier, prices, and item

用于查询的控制器代码

public function show($id)
    {
        $abstract = AbstractModel::find($id);
        $office = Office::all();
        $pr_item = PurchaseRequestItemModel::all()->where('pr_form_number',$abstract->pr_number);
        $grand_total = $pr_item->sum('pr_estimated_cost');

        $abstract_items = abstractitemmodel::all()->where('abstract_id',"=",$abstract->id);

        $query = DB::table('abstract_supplier')
                ->join('abstract_price', 'abstract_price.supplier_id', '=', 'abstract_supplier.id')
                ->join('abstract_items', 'abstract_items.id', '=', 'abstract_price.item_id')
                ->select(
                    'abstract_items.particulars',
                    'abstract_items.qty',
                    'abstract_items.unit',
                    'abstract_supplier.id',
                    'abstract_supplier.supplier',
                    'abstract_supplier.supplier_address',
                    'abstract_price.unit_price',
                    'abstract_price.total_price')
                ->paginate(3);

        $query2 = DB::table('abstract_supplier')->paginate(3);


        return view('abstract.abstract-form',compact('abstract','abstract_items','pr_item','grand_total','office','query','query2'));
    }

视图中表的代码

<table class="table table-responsive table-bordered table-condensed">
              <thead class="text-center">
                <tr class="center-t">
                    <th rowspan="3" class="col-xs-3">Particulars</th>
                    <th rowspan="3" class="col-xs-1">Qty</th>
                    <th rowspan="3" class="col-xs-1">Unit</th>

                    @forelse($query2 as $key => $suppliername)
                    <th colspan="2" class="col-xs-2">Supplier</th>      
                    @endforeach
                    @if($query2->count() < 3)
                        @for($i = $query2->count(); $i < 3; $i++)
                        <th colspan="2" class="col-xs-2">Supplier</th>
                        @endfor
                    @endif

                </tr>
                <tr>

                    @foreach($query2 as $indexKey => $suppliers)
                    <td colspan="2" class="col-xs-2 someCell">{{$suppliers->supplier}}</td>
                    @endforeach
                    @if($query2->count() < 3)
                        @for($i = $query2->count(); $i < 3; $i++)
                        <td colspan="2" class="col-xs-2">N/A</td>
                        @endfor
                    @endif



                </tr>
                <tr class="center-t">

                    @foreach($query2 as $key => $prices)
                    <th class="col-xs-1">Price/Unit</th>
                    <th class="col-xs-1">Price/Item</th>
                    @endforeach
                    @if($query2->count() < 3)
                        @for($i = $query2->count(); $i < 3; $i++)
                        <th class="col-xs-1">Price/Unit</th>
                        <th class="col-xs-1">Price/Item</th>
                        @endfor
                    @endif

                </tr>
              </thead>
              <tbody>
                @foreach($abstract_items as $key2 => $items)
                <tr>
                    <td>{{$items->particulars}}</td>
                    <td>{{$items->qty}}</td>
                    <td>{{$items->unit}}</td>
                    @foreach($query as $key3 => $prices)
                    <td  class="text-right">{{$prices->unit_price}}</td>
                    <td  class="text-right">{{$prices->total_price}}</td>
                    @endforeach
                    @if($query2->count() < 3)
                        @for($i = $query2->count(); $i < 3; $i++)
                        <td style="text-align: center;">N/A</td>
                        <td style="text-align: center;">N/A</td>
                        @endfor
                    @endif

                </tr>
                @endforeach
              </tbody>
            </table>

abstract_supplier,abstract_items,abstract_price的数据库结构

abstract_supplier

abstract_items

abstract_prices

问题

Result

0 个答案:

没有答案