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

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

    This Way:

    Post::with(array('user'=>function($query){
        $query->select('id','username');
    }))->get();
    

提交回复
热议问题