A one-to-one relationship means one record in a table is associated with only one record in another table.
Real-World Examples
- One User → One Profile
- One Student → One ID Card
- One Order → One Invoice
- One Company → One Address
01.Database Design
Example: User & Profile
users table
profiles table
📌 Rule
The foreign key is always placed in the related (child) table.
02. Create Models & Migrations
users migration
profiles migration
Run migrations:
03. Define Relationship in Models
User.php (Parent Model)
Profile.php (Child Model)
04. How Laravel Knows the Relationship
Laravel automatically assumes:
| Item | Value |
|---|---|
| Foreign key | user_id |
| Local key | id |
| Table name | profiles |
If you use custom names, you must define them manually.
