在 Dropdown Laravel Blade 中根据 table 中的字段在 optgroup 中显示选项

In Dropdown Laravel Blade show option in optgroup based upon a field in the table

我有一个 table 屏幕截图附在下面

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

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

也许 Laravel 辅助函数 groupBy() 可以帮助您。 控制器中的示例:

$cars = Cars::where('status', 1)->get();
    
$carModels = $cars->groupBy('model');

在blade中:

<select>
    @foreach($carModels as $model => $cars)
    
      <optgroup label="{{$model}}">
        @foreach($cars as $car)
          <option value="volvo">$c</option>
        @endforeach
      </optgroup>
    
    @endforeach
</select>