Initial commit: Lash Vanshy - Complete project with admin panel, gallery, products, and contact
This commit is contained in:
81
app/Models/AdminUser.php
Executable file
81
app/Models/AdminUser.php
Executable file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminUser extends Authenticatable
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'admin_users';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'rol',
|
||||
'avatar',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validar password
|
||||
*/
|
||||
public function validatePassword(string $password): bool
|
||||
{
|
||||
return Hash::check($password, $this->password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set password attribute - hash automatically
|
||||
*/
|
||||
public function setPasswordAttribute(string $value): void
|
||||
{
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope para filtrar super admins
|
||||
*/
|
||||
public function scopeSuperAdmin(Builder $query): Builder
|
||||
{
|
||||
return $query->where('rol', 'super_admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope para filtrar admins
|
||||
*/
|
||||
public function scopeAdmin(Builder $query): Builder
|
||||
{
|
||||
return $query->where('rol', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verificar si es super admin
|
||||
*/
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return $this->rol === 'super_admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Verificar si tiene permiso para gestionar otros admins
|
||||
*/
|
||||
public function canManageAdmins(): bool
|
||||
{
|
||||
return $this->rol === 'super_admin';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user