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

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

    I know, you ask for Eloquent but you can do it with Fluent Query Builder

    $data = DB::table('themes')
        ->join('users', 'users.id', '=', 'themes.user_id')
        ->get(array('themes.*', 'users.username'));
    

提交回复
热议问题