Laravel-strtolower()期望参数1为字符串,给定对象

tor*_*ili -1 php laravel

我试图按第一个字符对标签进行分组

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为字符串,给定对象

Jon*_*eir 5

您不能使用闭包对查询进行分组,只能使用结果集合:

...->orderBy(...)->get()->groupBy(...);
Run Code Online (Sandbox Code Playgroud)