user roles, bug fixes
This commit is contained in:
@@ -6,6 +6,8 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use App\Models\ErpSystemRole;
|
||||
|
||||
class StaffMember extends Authenticatable
|
||||
{
|
||||
@@ -35,7 +37,22 @@ class StaffMember extends Authenticatable
|
||||
public function department(){
|
||||
return $this->hasOne('App\Models\Department', 'id', 'department_id');
|
||||
}
|
||||
// public function designation(){
|
||||
// return $this->hasOne('App\Models\Department', 'id', 'department_id');
|
||||
// }
|
||||
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
// Parameter order: Related Model, Pivot Table Name, Foreign Key on Pivot, Related Key on Pivot
|
||||
return $this->belongsToMany(ErpSystemRole::class, 'user_roles', 'staff_member_id', 'system_role_id');
|
||||
}
|
||||
|
||||
public function hasRole(string $role): bool
|
||||
{
|
||||
return $this->roles()->where('name', $role)->exists();
|
||||
}
|
||||
|
||||
|
||||
// 4. Cast dates correctly
|
||||
protected $casts = [
|
||||
// 'dob' => 'date',
|
||||
|
||||
Reference in New Issue
Block a user