我有這個函式從表格中獲取資料分頁并將資料傳遞給視圖
public function job_requests(){
$orders = DB::table('orders')
->select('id','order_data','order_status')
->paginate(5);
return view('autorepair/mechanics/job_requests',compact('orders'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
該列order_data包含以下格式的資料
{
"personal_data": {
"email": "[email protected]",
"telephone_number": "0999",
"postal_address": "LON",
"car_registration": "GB BHG"
},
"inperson_diagnostic": {
"diagnostic_inspection": "67.30",
"car_wont_start_inspection": "67.30",
"plugin_diagnostic_inspection": "67.30"
},
"tyres": {
"front_wheels": 1,
"rear_wheels": 1,
"wheel_width": 45,
"wheel_profile": 1,
"wheel_rim": 1,
"speed_rating": "w",
"final_price": 90
},
"servicing_and_mot": {
"mot_with_collection_delivery": 75,
"major_service": 304.52,
"full_service": 203.45,
"interim_service": "149.70",
"vehicle_health_check": 50
},
"inspection_services": {
"premium_prepurchase_inspection": 146.38,
"standard_prepurchase_inspection": 104,
"basic_prepurchase_inspection": 86.44
},
"repairs": {
"ABS wheel speed sensor replacement": 964,
"ABS pump replacement": 712,
"Brake pedal switch replacement": 568,
"Air conditioning regas (R1234yf Gas ONLY)": 469
}
}
在我看來我有這個
@if(!$orders->isEmpty())
<table class="table table-bordered">
<tr>
<th>No</th>
<th>Order Status</th>
<th>Order Data</th>
<th width="280px">Action</th>
</tr>
@foreach ($orders as $order)
<tr>
<td>{{ $i }}</td>
<td>{{ $order->order_status }}</td>
<td>{{ $order->order_data}}</td>
<td>
<a class="btn btn-info" href="{{ url('/view_product/' . $order->id) }}">Show</a>
<a hljs-string">" href="{{ url('/edit_product/' . $order->id ) }}">Accept</a>
</td>
</tr>
@endforeach
</table>
@else
<p>No orders yet.</p>
@endif
{!! $orders->links() !!}
我可以在這里顯示 josn 資料,$order->order_data但我想先對其進行解碼。如何將解碼的陣列傳遞給我的視圖并能夠保留分頁鏈接?
uj5u.com熱心網友回復:
您可以在視圖中對其進行解碼。
根據order_data實際傳遞給視圖的格式(請原諒,我不知道 builder 或 eloquent 如何檢索 jsonb 型別),但您可以在視圖中使用 dd() 或 gettype() 來幫助確定order_data傳遞到視圖時的資料型別):
- 如果內容作為字串進入視圖,請嘗試
json_decode()使用該order_data值。如果這是您的意圖,我認為您應該能夠迭代其結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/461951.html
標籤:拉拉维尔
下一篇:顯示電影的流派標簽
