Support the ongoing development of →
Database Eloquent
Last updated 1 year ago.

Are you ure you want to group by user_id? What are you trying to do?

Last updated 1 year ago.

@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','']);
select name, post from `articles` where `user_id` = ?
select name from `users` where `user`.`id` in (?)
SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'field list' (SQL: select `name`, `post`, `user`.`name` from `articles` where `user_id` = 1)

same error.

Last updated 1 year ago.

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']);
Last updated 1 year ago.

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

iClosedz iclosedz Joined 10 Jul 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.