Many-to-One Relationship means that multiple records from one table are connected to a single record in another table.

Many records are connected to one record.

  • Many profiles belong to one user.
  • Profile 1 belongs to Mahendra
  • Profile 2 belongs to Mahendra
  • Profile 3 belongs to Amit
  • Many Profiles belong to One User

Profile Model:

In Many-to-One relationship, child table uses belongsTo()

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
?>

Fetch User from Profile:

$profile = Profile::find(1);

echo $profile->user->name;