How to join three table by laravel eloquent model

后端 未结 3 1878
悲&欢浪女
悲&欢浪女 2020-11-27 10:36

I have three table

Articles table

 id
 title
 body
 categories_id
 user_id

Categories table

  id
  category         


        
3条回答
  •  时光说笑
    2020-11-27 11:10

    Try:

    $articles = DB::table('articles')
                ->select('articles.id as articles_id', ..... )
                ->join('categories', 'articles.categories_id', '=', 'categories.id')
                ->join('users', 'articles.user_id', '=', 'user.id')
    
                ->get();
    

提交回复
热议问题