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

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

    On Laravel 5.5, the cleanest way to do this is:

    Theme::with('user:userid,name,address')->get()
    

    You add a colon and the fields you wish to select separated by a comma and without a space between them.

提交回复
热议问题