gpt4 book ai didi

php - 在 Dropdown Laravel Blade show option in optgroup based on a field in the table

转载 作者:搜寻专家 更新时间:2023-10-31 21:21:14 27 4
gpt4 key购买 nike

我有一张表格,下面附有屏幕截图 database image

我想显示所有的账户类型,但它应该显示在选项组中

select image

我怎样才能做到这一点???

dropdown image

最佳答案

Laravel 的辅助函数 groupBy() 会帮你解决这个问题。数据分组示例:

$cars = Car::where('status', 1)->get();

$carModels = $cars->groupBy('model');

Blade 示例:

<select name="car_id">
@foreach($carModels as $model => $cars)

<optgroup label="{{ $model }}">
@foreach($cars as $car)
<option value="{{ $car->id }}">{{ $car->name }}</option>
@endforeach
</optgroup>

@endforeach
</select>

关于php - 在 Dropdown Laravel Blade show option in optgroup based on a field in the table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47902801/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com