Laravel Eloquent: How to get only certain columns from joined tables

前端 未结 15 2519
礼貌的吻别
礼貌的吻别 2020-12-02 07:57

I have got 2 joined tables in Eloquent namely themes and users.

theme model:

public function user() {
  return $this->belongs_to(         


        
15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 08:31

    If I good understood this what is returned is fine except you want to see only one column. If so this below should be much simpler:

    return Response::eloquent(Theme::with('user')->get(['username']));
    

提交回复
热议问题