From c670d6a2fe6cf4cd3f0cd58ea5d99fd9ef7f3955 Mon Sep 17 00:00:00 2001 From: Hasin Hayder Date: Fri, 20 May 2022 22:22:30 +0600 Subject: [PATCH] Inverse of Relationship - Role belongs to many User --- app/Models/Role.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Models/Role.php b/app/Models/Role.php index 6d5a878..991be4d 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use App\Models\User; class Role extends Model { @@ -16,4 +17,8 @@ class Role extends Model 'created_at', 'updated_at', ]; + + public function users(){ + return $this->belongsToMany(User::class,'user_roles'); + } }