小编Arl*_*ari的帖子

带有不同的值

我正在尝试从数据库中检索数据并将它们绑定到html选择标记,并绑定它们我需要使用pluck所以我得到我希望在数组中显示的字段(key => value),因为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'
    ];
}
Run Code Online (Sandbox Code Playgroud)

虽然我在控制器中使用的功能看起来像:

public function getRooms()
    {
        $roomType = Room::pluck('type','type');
        $roomFloor = Room::pluck('floor','floor');

        return view('roomgrid')->with('type',$roomType)->with('floor',$roomFloor);
    }
Run Code Online (Sandbox Code Playgroud)

我的视图包含这段代码来获取楼层:

{{FORM::select('floor', $floor, null,['class'=>'basic'])}}
Run Code Online (Sandbox Code Playgroud)

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

distinct laravel pluck laravelcollective

10
推荐指数
4
解决办法
1万
查看次数

标签 统计

distinct ×1

laravel ×1

laravelcollective ×1

pluck ×1