sintonia_webapp/app/Models/User.php

116 lines
2.7 KiB
PHP

<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Filters\UserFilters;
use App\Models\Show\ShowHosts;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
protected $table = 'cc_subjs';
protected $guard_name = 'web';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'login',
'email',
'pass',
'type'
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'pass',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
/**
* Map application attribute names to database column names.
*/
protected array $attributeMap = [
'username' => 'login', // Map 'username' to 'login'
'password' => 'pass', // Map 'password' to 'pass'
];
/**
* Override the getAttribute method to use the attribute map.
*/
public function getAttribute($key)
{
// Check if the key exists in the attribute map
if (array_key_exists($key, $this->attributeMap)) {
return $this->attributes[$this->attributeMap[$key]];
}
// Fall back to the default behavior
return parent::getAttribute($key);
}
/**
* Override the setAttribute method to use the attribute map.
*/
public function setAttribute($key, $value)
{
// Check if the key exists in the attribute map
if (array_key_exists($key, $this->attributeMap)) {
$this->attributes[$this->attributeMap[$key]] = $value;
return;
}
// Fall back to the default behavior
parent::setAttribute($key, $value);
}
/**
* Specify the password column for authentication.
*/
public function getAuthPassword()
{
return $this->pass;
}
/**
* Specify the login column for authentication.
*/
public function username()
{
return 'login';
}
public function scopeSearchFilter($query, $request)
{
$filters = new UserFilters();
return $filters->apply($query, $request);
}
public function showDjs()
{
return $this->hasMany(ShowHosts::class, 'subjs_id');
}
}