Tag Archives: hasmany relation example in laravel

fetch-data-with-model-relationship-in-laravel-7

Fetch data with model relationship in laravel 7

Hello World, Welcome to projectsplaza.com. Today we will discuss how we can fetch data with the model relationship in laravel 7. In this tutorial, we will create an example of hasMany and belongsTo model relationship.


hasMany Relationship

Suppose you have a blog website and you want to fetch comments of a specific post on the post detail page. In this scenario, you should have two models, Post and Comment respectively. We know that a single post has many comments so we will define the hasMany relationship in the post model.

Continue reading