Eloquent Relationship Generator Laravel 5.x+
- Home
- > Web Dev > Laravel Tools >
- Eloquent Relationship Generator
Generated PHP Code
How to Use
- Source Model — The model that defines the relationship (e.g.,
User). - Target Model — The related model (e.g.,
Post). - Relationship Type — Choose the relationship type that matches your database schema.
- Keys — Optional foreign key and local key overrides if you're not following Laravel's conventions.
Relationship Reference
- hasOne — One-to-one (e.g., User has one Profile). Foreign key in target table.
- hasMany — One-to-many (e.g., User has many Posts). Foreign key in target table.
- belongsTo — Inverse one-to-one/many (e.g., Post belongs to User). Foreign key in source table.
- belongsToMany — Many-to-many (e.g., User belongsToMany Role). Uses pivot table.