Eloquent Relationships: Connecting Your Data
Learn one-to-many relationships like users and posts using Eloquent.
Natalie Reed
September 24, 2025
3.7k108
Most applications have related data.
One user has many posts
User model:
public function posts() {
return $this->hasMany(Post::class);
}
Post model:
public function user() {
return $this->belongsTo(User::class);
}
Use relationship
$user = User::find(1);
$posts = $user->posts;
Flow
flowchart LR
A[User] --> B[hasMany]
B --> C[Posts]
In the next tutorial, we will build full CRUD using resource controllers.
#Laravel#Eloquent#Database#Intermediate