Files
new_raffles/app/Models/User.php
2025-07-27 17:40:56 +05:45

77 lines
1.7 KiB
PHP

<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Modules\Employee\Models\Employee;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'can_login',
'active_sidebar',
'order'
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
public function canLogin(): bool
{
return $this->can_login;
}
public function getRoles()
{
return $this->roles->map(function ($role) {
return "<span class='badge bg-primary p-1'>{$role->name}</span>";
})->implode(' ');
}
public function employee()
{
return $this->belongsTo(Employee::class, "user_id");
}
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'can_login' => 'boolean',
];
}
public static function getFillableFields()
{
return (new static())->getFillable();
}
}