added user roles relationship

This commit is contained in:
Cüneyt Şentürk 2022-07-20 17:22:01 +03:00
parent 894c2cef1a
commit 61670c1f2d
2 changed files with 41 additions and 0 deletions

View File

@ -94,6 +94,11 @@ class User extends Authenticatable implements HasLocalePreference
return $this->hasOne('App\Models\Auth\UserInvitation', 'user_id', 'id');
}
public function roles()
{
return $this->belongsToMany('App\Models\Auth\Role', 'App\Models\Auth\UserRole');
}
/**
* Always capitalize the name when we retrieve it
*/

View File

@ -0,0 +1,36 @@
<?php
namespace App\Models\Auth;
use App\Abstracts\Model;
class UserRole extends Model
{
protected $table = 'user_roles';
protected $tenantable = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['user_id', 'role_id', 'user_type'];
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
public function user()
{
return $this->belongsTo('App\Models\Auth\User');
}
public function role()
{
return $this->belongsTo('App\Models\Auth\Role');
}
}