Skip to content
Advertisement

Get all data where pivot id (Laravel)

Is there the best way/the simplest way to get all data where pivot? I tried this $article = Article::with('category')->wherePivot('category_id', $category)->get(); but i got error

JavaScript

The relation is many to many

Article

  • id
  • content
JavaScript

Articles_Has_Categories

  • id
  • article_id
  • category_id
JavaScript

Category

  • id
  • name
JavaScript

Advertisement

Answer

Please try this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement