staff update
This commit is contained in:
@@ -1,22 +1,43 @@
|
||||
<?php
|
||||
|
||||
// app/Models/Admin.php
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class Admin extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
use HasFactory, Notifiable, HasRoles;
|
||||
|
||||
protected $guard = 'admin';
|
||||
protected $guard_name = 'admin';
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'role',
|
||||
'name', 'email', 'password', 'username',
|
||||
'phone', 'emergency_phone', 'address',
|
||||
'role', 'department', 'designation', 'joining_date',
|
||||
'status', 'additional_info', 'type', // admin/staff indicator
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
public function setPasswordAttribute($value)
|
||||
{
|
||||
if (!$value) return;
|
||||
|
||||
if (Hash::needsRehash($value)) {
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
} else {
|
||||
$this->attributes['password'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDisplayNameAttribute()
|
||||
{
|
||||
return "{$this->name}";
|
||||
}
|
||||
}
|
||||
|
||||
81
app/Models/Staff.php
Normal file
81
app/Models/Staff.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class Staff extends Authenticatable
|
||||
{
|
||||
use Notifiable, HasRoles, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The guard name used by Spatie.
|
||||
* Make sure this matches the guard you'll use for admin/staff auth (usually 'web' or 'admin').
|
||||
*/
|
||||
protected $guard_name = 'admin';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'employee_id',
|
||||
'name',
|
||||
'email',
|
||||
'phone',
|
||||
'emergency_phone',
|
||||
'address',
|
||||
'role', // business role/title (not Spatie role)
|
||||
'department',
|
||||
'designation',
|
||||
'joining_date',
|
||||
'status',
|
||||
'additional_info',
|
||||
'username',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* Hidden attributes (not returned in arrays / JSON).
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* Casts
|
||||
*/
|
||||
protected $casts = [
|
||||
'joining_date' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Mutator: automatically hash password when set.
|
||||
* Accepts plain text and hashes it with bcrypt.
|
||||
*/
|
||||
public function setPasswordAttribute($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If already hashed (starts with $2y$), don't double-hash
|
||||
if (Hash::needsRehash($value)) {
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
} else {
|
||||
$this->attributes['password'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional helper to get display name (useful in views/logs).
|
||||
*/
|
||||
public function getDisplayNameAttribute()
|
||||
{
|
||||
return $this->name . ' (' . $this->employee_id . ')';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user