user roles, bug fixes

This commit is contained in:
Kwesi Banson
2026-10-13 14:29:40 +00:00
parent 40162f3080
commit 8428d94abd
14 changed files with 366 additions and 9 deletions

View File

@@ -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',