//Earlier in the code, in each Model:
query = ModelName::select('table_name.*')
//Later in the code in a function in a Trait class that is always called
if ($column == 'group_by')
{
$thing_query->groupBy($value);
$thing_query->select(DB::raw('COUNT('.$value.') as count'));
}
有没有办法在 eloquent 查询构建器中附加或包含单独的选择函数?
实际的 ->select() 设置较早,然后调用此函数。我想在稍后将查询传递给它的函数中有条件地添加计数列。