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

前端 未结 15 2490
礼貌的吻别
礼貌的吻别 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:25

    Change your model to specify what columns you want selected:

    public function user() {
      return $this->belongs_to('User')->select(array('id', 'username'));
    }
    

    And don't forget to include the column you're joining on.

提交回复
热议问题