我在 L5 中正确连接表格时遇到困难。
这加入了我的文章
和用户表
:
$articles = DB::table('articles')
->join('users', function($join)
{
$join->on('articles.author', '=', 'users.id');
})
->select('articles.id as id',
'articles.title as title',
'users.username as username',
'articles.created_at as created_at')
->latest('articles.created_at')
->get();
一切似乎都正常,但它没有考虑 articles.author
的 null
值。我无法正确理解外部连接的语法。
此外,如果我的查询的其余部分编写正确,请告诉我。
最佳答案
leftJoin()
似乎是外连接的正确语法。这纠正了我的问题。
关于php - Laravel 表连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29954740/