美文网首页
关联模型 相关

关联模型 相关

作者: berger_w | 来源:发表于2019-03-27 15:53 被阅读0次

// 获得所有至少有一条评论的文章...

$posts = App\Post::has('comments')->get();

// 获得所有有三条或三条以上评论的文章...

$posts = Post::has('comments', '>=', 3)->get();

// 获得所有至少有一条获赞评论的文章...

$posts = Post::has('comments.votes')->get();

// 获得所有至少有一条评论内容满足 foo% 条件的文章

$posts = Post::whereHas('comments', function ($query) {

    $query->where('content', 'like', 'foo%');})

->get();

相关文章

网友评论

      本文标题:关联模型 相关

      本文链接:https://www.haomeiwen.com/subject/ccnzvqtx.html