我试图按第一个字符对标签进行分组
return $tags->select('id', 'title')
->orderBy('title','asc')
->groupBy(function($item, $key) {
return substr($item['title'], 1, 1);
})
->get();
Run Code Online (Sandbox Code Playgroud)
但它返回此错误
strtolower()期望参数1为字符串,给定对象
您不能使用闭包对查询进行分组,只能使用结果集合:
...->orderBy(...)->get()->groupBy(...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3329 次 |
| 最近记录: |