【发布时间】:2021-02-19 12:40:35
【问题描述】:
我正在尝试从我的数据库表“order”中的特定列“category”单独显示值,该表是一个包含“value1,value2,value3”等值的数组。
我想获取这些值并在 laravel Blade 中单独显示它们。 $order->category[1] 之类的东西。我不知道该怎么做,因为我仍然想同时显示其他列中的所有值。
这是我的控制器:
public function index()
{ $orders = DB::table('order')
->where('email', auth()->user()->email)
->get();
return view('dashboard', [
'orders' => $orders,
]);
}
这是我的刀片:
@foreach ($orders->reverse() as $key => $order )
<div class="layout__primary">
<div class="works header-item2">
<div class="item-text2">{{ $order->name }}</div>
<img src="{{ $order->category[1] }}" class="works-img" style="max-width: 280px">
<div class="item-labels">{{ $order->category[2] }}</div>
</div>
</div>
@endforeach
还有 dd($order)
Illuminate\Support\Collection {#1374 ▼
#items: array:1 [▼
0 => {#1386 ▼
+"id": 50
+"name": "Name"
+"email": "email@hotmail.com"
+"mobile": 12348890
+"category": "Personal,assets/img/personal.png,Personal Website"
+"contact": "email"
+"domain": null
+"new_domain": null
+"alojamento": null
+"criar_email": null
+"facebook": null
+"instagram": null
+"linkedin": null
+"plan": null
+"order_date": "2021-02-19 12:06:48"
+"state": "Processing"
}
]
}
【问题讨论】:
-
dd($orders);的输出是什么 -
@user15070659 我现在用输出更新了问题
-
向我们展示您使用的表顺序、类别和反向关系的数据库架构?
-
你可以把$order->分类放在","字符上,这样就变成了一个数组。
-
@GertB。是的,但我如何将它传递给视图和显示?