Are you ure you want to group by user_id
? What are you trying to do?
@kokokurak This is sample like sudo code.
But I think group by is not a problem.
if I use
$article = new Article();
$query = $article->with('user')
->where('user_id', '=', 1)
$user = $query->get(['name','post','user.name']);
select name, post from `articles` where `user_id` = ?
select name from `users` where `user`.`id` in (?)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user.name' in 'field list' (SQL: select `name`, `post`, `user`.`name` from `articles` where `user_id` = 1)
same error.
Can not try myself, byt try this:
$article = Article::with(array('user' => function($query)
{
$query->select('id','name as username');
}
))->where('user_id', '=', 1)
->get(['name', 'post']);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community