Laravel Eloquent Filter By Column of Relationship

前端 未结 1 1347
独厮守ぢ
独厮守ぢ 2020-12-08 14:10

Using the Eloquent ORM I have my models set up like so: Post belongsToMany Category

Post.php

public function c         


        
相关标签:
1条回答
  • 2020-12-08 14:57

    I can't access my Vagrant box right now, but I believe this should work:

    $posts = Post::whereHas('categories', function($q)
    {
        $q->where('slug', '=', Input::get('category_slug'));
    
    })->get();
    
    0 讨论(0)
提交回复
热议问题