我想用eloquent(Laravel 4.2)向数据库发出请求..我有GROUP_CONCAT
SQL函数的问题:
$articles = Article::join('tags', function ($join) {
$join->on('articles.id', '=', 'tags.article_id');
})->get(array('articles.*', 'GROUP_CONCAT(tags.tag_id SEPARATOR ', ') as tags'));
我收到了这个SQL错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'GROUP_CONCAT(tags.tag_id SEPARATOR ' in 'field list' (SQL: select `articles`.*, `GROUP_CONCAT(tags`.`tag_id SEPARATOR `, `)` as `tags` from `articles` inner join `tags` on `articles`.`id` = `tags`.`article_id`
答案 0 :(得分:0)
您需要raw expression:
$articles = DB::table('articles')
->select(DB::raw('articles.*', 'GROUP_CONCAT(tags.tag_id SEPARATOR ', ') as tags'))
->join('tags', function ($join) {
$join->on('articles.id', '=', 'tags.article_id');
})->get();