ldc-gen-game-web/app/Models/User.php
Jérémy Munsch 2831d422c9
Refactorize Settings BO save
- require composer kwaadpepper/enum
- User->role is now an enum
- Add isLocal and isAdmin to user model
- changed multiple fields casts on model Settings
- added validation for settings
2022-03-11 09:59:40 +01:00

94 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use App\Enums\UserRole;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Kwaadpepper\Enum\Traits\CastsEnums;
class User extends Authenticatable
{
use Notifiable;
use CastsEnums;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'crm_id',
'civility',
'firstname',
'lastname',
'birth_date',
'email',
'password',
'address',
'address2',
'town',
'postal_code',
'country',
'email_verify_token',
'email_verified'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Map attribute names to enum classes.
*
* @var array
*/
protected $enumCasts = [
'role' => UserRole::class
];
/**
* Has Many Participation relation
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function participations()
{
return $this->hasMany(Participation::class, 'user_id');
}
/**
* Check if user is admin.
*
* @return boolean
*/
public function isAdmin(): bool
{
return $this->role->equals(UserRole::admin());
}
/**
* Check if user is local.
*
* @return boolean
*/
public function isLocal(): bool
{
return $this->role->equals(UserRole::admin()) or
$this->role->equals(UserRole::brand());
}
}