131 lines
3.2 KiB
PHP
131 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\CrudAction;
|
|
use App\Enums\CrudType;
|
|
use App\Enums\Role;
|
|
use App\Traits\IsCrudModel;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory;
|
|
use Notifiable;
|
|
use CastsEnums;
|
|
use IsCrudModel;
|
|
|
|
protected $enumCasts = [
|
|
'role' => Role::class
|
|
];
|
|
|
|
protected $crudLabelColumn = 'name';
|
|
|
|
protected $crudValueColumn = 'id';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
];
|
|
|
|
/**
|
|
* 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',
|
|
];
|
|
|
|
public function __construct($attributes = [])
|
|
{
|
|
self::$editableProperties = [
|
|
'name' => [
|
|
'label' => trans('Nom'),
|
|
'type' => CrudType::string(),
|
|
'validate' => [
|
|
'string',
|
|
'max:255'
|
|
],
|
|
'required' => true,
|
|
'nullable' => false,
|
|
'actions' => [
|
|
CrudAction::viewAny(),
|
|
CrudAction::view(),
|
|
CrudAction::create(),
|
|
CrudAction::update(),
|
|
]
|
|
],
|
|
'email' => [
|
|
'label' => trans('Email'),
|
|
'type' => CrudType::email(),
|
|
'required' => true,
|
|
'nullable' => false,
|
|
'validate' => [
|
|
'max:255'
|
|
],
|
|
'actions' => [
|
|
CrudAction::viewAny(),
|
|
CrudAction::view(),
|
|
CrudAction::create(),
|
|
CrudAction::update(),
|
|
]
|
|
],
|
|
'projects' => [
|
|
'label' => trans('Projets'),
|
|
'type' => CrudType::belongsToMany(),
|
|
'belongsToMany' => Project::class,
|
|
'belongsToManyLabel' => 'name',
|
|
'readonly' => function () {
|
|
return auth()->user()->role->equals(Role::admin()) ? false : true;
|
|
},
|
|
'actions' => [
|
|
CrudAction::viewAny(),
|
|
CrudAction::view(),
|
|
CrudAction::create(),
|
|
CrudAction::update(),
|
|
]
|
|
]
|
|
];
|
|
parent::__construct($attributes);
|
|
}
|
|
|
|
public function tickets()
|
|
{
|
|
return $this->hasMany(Ticket::class, 'created_by');
|
|
}
|
|
|
|
public function messages()
|
|
{
|
|
return $this->hasMany(Messages::class, 'user_id');
|
|
}
|
|
|
|
public function subscriptions()
|
|
{
|
|
return $this->belongsToMany(Ticket::class, 'subscriptions');
|
|
}
|
|
|
|
public function projects()
|
|
{
|
|
return $this->belongsToMany(Project::class);
|
|
}
|
|
}
|