如何根据 "enum" 列获得分类 laravel eloquent 结果并在一页中显示?

How to get categorized laravel eloquent results based on "enum" column and show them in one page?

为了简单起见,我将解释一个伪情况:

有个users table:

id  |  name  |  status
-----------------------

status 列是 enum 并且可以有 3 个不同的值:deadsickhealthy

现在我想在一页中显示所有 usersdead 个用户在上面,sick 个用户在中间,healthy 个用户在底部!

我必须执行三个查询吗?并一一传递给大家看? 像这样:

$dead = User::where('status','dead')->get();
$sick = User::where('status','sick')->get();
$healthy = User::where('status','healthy')->get();

或者有更好的方法?如果有 10 个状态呢?还是 100?

更新:

我正在寻找查询性能。

您需要使用groupBy功能

$users = User::get()->groupBy('status');

结果会像

[
    'dead' => [
        //items of dead type
    ],
    'healthy' => [
                   //items of healthy type
    ],
    'sick' => [
                   //items of sick type
    ]
]

您可以访问以下类型的数据:

$users['dead'];