partial update create mutations workflow
This commit is contained in:
@@ -75,4 +75,61 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasOne(Dealer::class, 'id', 'dealer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role associated with the User
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class, 'role_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has a specific role
|
||||
*
|
||||
* @param string $roleName
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRole($roleName)
|
||||
{
|
||||
// If role_id is 0 or null, user has no role
|
||||
if (!$this->role_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// For admin role, we can check if user has admin privileges
|
||||
if (strtolower($roleName) === 'admin') {
|
||||
return $this->isAdmin();
|
||||
}
|
||||
|
||||
// Load role if not already loaded
|
||||
if (!$this->relationLoaded('role')) {
|
||||
$this->load('role');
|
||||
}
|
||||
|
||||
return $this->role && strtolower($this->role->name) === strtolower($roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is admin by checking admin privileges
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdmin()
|
||||
{
|
||||
// Check if user has admin privileges by checking if they can access admin area
|
||||
try {
|
||||
$adminPrivilege = \App\Models\Privilege::join('menus', 'menus.id', '=', 'privileges.menu_id')
|
||||
->where('menus.link', 'adminarea')
|
||||
->where('privileges.role_id', $this->role_id)
|
||||
->where('privileges.view', 1)
|
||||
->first();
|
||||
|
||||
return $adminPrivilege !== null;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user