Distinct values with pluck

Room::unique('floor')->pluck('floor', 'floor');

Why not use groupBy()?

$roomType = Room::groupBy('type')->pluck('type','type');

distinct can do the trick:

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

Which will be translated into the following SQL:

SELECT DISTINCT type FROM rooms

2019 Update

You don't need to use 2 arguments with pluck()

simply do:

$roomType = Room::groupBy('type')->pluck('type');

of course for getting it into array:

$roomType = Room::groupBy('type')->pluck('type')->toArray();

Sometimes I use the result for whereIn clause, its useful for that.