*/ protected $fillable = [ 'name', 'email', 'password', 'root_admin', ]; /** * Rules verifying that the data being stored matches the expectations of the database. */ public static array $validationRules = [ 'email' => 'required|email|between:1,191|unique:users,email', 'name' => 'required|string|between:1,191', 'password' => ['sometimes', 'min:8', 'max:191', 'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})/u', 'string'], 'root_admin' => 'boolean', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'email_verified_at', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'root_admin' => 'boolean', ]; public function toReactObject(): array { return Collection::make($this->toArray())->except(['id'])->toArray(); } public function createToken( string $name, ApiKeyType $type, array $abilities = ['*'], ): NewAccessToken { $token = $this->tokens()->create([ 'type' => $type, 'name' => $name, 'token' => hash('sha256', $plainTextToken = Str::random(40)), 'abilities' => $abilities, ]); return new NewAccessToken($token, $token->getKey() . '|' . $plainTextToken); } public function servers(): HasMany { return $this->hasMany(Server::class); } public function getRouteKeyName(): string { return 'id'; } protected static function boot(): void { parent::boot(); static::creating(function (User $user) { $user->uuid = Str::uuid()->toString(); }); } }