Skip to content

Instantly share code, notes, and snippets.

@yfktn
Created April 7, 2014 03:01
Show Gist options
  • Select an option

  • Save yfktn/10014244 to your computer and use it in GitHub Desktop.

Select an option

Save yfktn/10014244 to your computer and use it in GitHub Desktop.
Get all Posts that are belongs to a category ...
/**
* assume Post has belongsToMany relationship with Category, and Category has belongsToMany relationship with Post named posts
*
* we need to get all posts that belongs to a category ...
*/
$posts = Category::find($idCategory)->posts()->get();
// test
foreach($posts as $p)
{
echo "{$p->id}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment