ldc-gen-game-web/app/Models/User.php

95 lines
1.8 KiB
PHP
Raw Normal View History

2020-10-21 15:26:21 +02:00
<?php
namespace App\Models;
2020-10-21 15:26:21 +02:00
use App\Enums\UserRole;
2020-10-21 15:26:21 +02:00
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Kwaadpepper\Enum\Traits\CastsEnums;
2020-10-21 15:26:21 +02:00
class User extends Authenticatable
{
use Notifiable;
use CastsEnums;
2020-10-21 15:26:21 +02:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
2020-10-29 15:40:23 +01:00
'crm_id',
'civility',
'firstname',
'lastname',
'birth_date',
'email',
'password',
'address',
'address2',
'town',
'postal_code',
'country',
'email_verify_token',
'email_verified'
2020-10-21 15:26:21 +02:00
];
/**
* 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
*/
2021-08-18 17:08:02 +02:00
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());
}
2020-10-21 15:26:21 +02:00
}