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); } }