我将控制器中的数组传递给视图,如下所示:
$Client_Package_Items = DB::table('client__package__items')
->join('treatments', 'client__package__items.treatment_id', '=', 'treatments.id')
->get();
return view('Sales.show')
->with('Client_Package_Items', $Client_Package_Items);
当我单击包含此数组中ID值的不同按钮时,我想创建一个仅包含该数组中某些数据的循环。
这是我的观点:
<div class="modal fade" id="redeem{{$c->id}}">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header bg-success text-white">
<h4 class="modal-title">Top up Package Serial No. {{$c->id}}</h4>
{{Form::hidden('client_package_id', $c->id)}}
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row mt-3">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
@foreach($Client_Package_Items as $cpi)
{{$cpi->treatment}}
@endforeach
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
{{Form::hidden('sale_type_id', 3)}}
{{Form::hidden('client_id', $Clients->id)}}
{{Form::submit('Top-up', ['class'=>'btn btn-success submitBtn',])}}
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
我需要对照数组检查$ c-> id并仅显示包含$ c-> id的数据数组。
预先感谢您的帮助。
答案 0 :(得分:0)
将selectraw添加到查询中
$Client_Package_Items = DB::table('client__package__items')
->join('treatments', 'client__package__items.treatment_id', '=', 'treatments.id')
->SelectRaw('client_package_items.id as id ,...') //add this
->get();