i am trying to group tags by first character
return $tags->select('id', 'title')
->orderBy('title','asc')
->groupBy(function($item, $key) {
return substr($item['title'], 1, 1);
})
->get();
but it returns this error
strtolower() expects parameter 1 to be string, object given
您不能使用闭包对查询进行分组,只能使用结果集合:
...->orderBy(...)->get()->groupBy(...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.