gpt4 book ai didi

laravel - 不同的值(value)观与采摘

转载 作者:行者123 更新时间:2023-12-04 02:45:06 26 4
gpt4 key购买 nike

我正在尝试从数据库中检索数据并将它们绑定(bind)到 html 选择标记,并且为了绑定(bind)它们我需要使用 pluck 所以我得到了我想在数组中显示的字段(键 => 值),因为 FORM: :选择。正常的采摘得到所有的结果,而我想使用不同的。我的模型是房间,它看起来像:

    class Room extends Eloquent
{
public $timestamps = false;

protected $casts = [
'price' => 'float',
'floor' => 'int',
'size' => 'float'
];

protected $fillable = [
'capacity',
'description',
'price',
'floor',
'size',
'type',
'photo_name'
];
}

虽然我在 Controller 中使用的功能如下所示:
public function getRooms()
{
$roomType = Room::pluck('type','type');
$roomFloor = Room::pluck('floor','floor');

return view('roomgrid')->with('type',$roomType)->with('floor',$roomFloor);
}

我的 View 包含这段代码来获得楼层:
{{FORM::select('floor', $floor, null,['class'=>'basic'])}}

像这样我得到重复的楼层,这是我不想要的。有什么办法可以让我得到不同的地板并采摘它们吗?提前致谢。

最佳答案

distinct可以做到这一点:

Room::query()->distinct()->pluck('type');

这将被翻译成以下SQL:
SELECT DISTINCT type FROM rooms

关于laravel - 不同的值(value)观与采摘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42447682/

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