Eloquent Relationships: Connecting Your Data
Learn one-to-many relationships like users and posts using Eloquent.
Natalie Reed
December 21, 2025
0.0k0
Most applications have related data. ## One user has many posts User model: ```php public function posts() { return $this->hasMany(Post::class); } ``` Post model: ```php public function user() { return $this->belongsTo(User::class); } ``` ## Use relationship ```php $user = User::find(1); $posts = $user->posts; ``` ## Flow ```mermaid 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