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

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

    This is how i do it

    $posts = Post::with(['category' => function($query){
            $query->select('id', 'name');
          }])->get();
    

    First answer by user2317976 did not work for me, i am using laravel 5.1

提交回复
热议问题