Level 1
You need to use One to one Relation (belongsTo) in Article Model and Category model in One to many (hasMany)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm working on a small project and I would like to know what kind of relationship I need to use to get a list of my articles in a category
( by the way each article have only one category )
this is my articles table:
id ,title, content, category_id
This is my categories table:
id, name
and I have two models ( Article and Category ), so how I can get all the articles of category number 1 for example ( what kind of relationship I need )
Please or to participate in this conversation.