*/ protected $fillable = [ 'user_id', 'vault_id', 'uri', 'capabilities', 'username', 'password', 'sync_way', 'distant_sync_token', 'current_logid', 'frequency', 'last_synchronized_at', 'active', ]; /** * The attributes that aren't mass assignable. * * @var array|bool */ protected $guarded = ['id']; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'user_id' => 'string', 'vault_id' => 'string', 'last_synchronized_at' => 'datetime', 'active' => 'boolean', 'capabilities' => 'array', 'current_logid' => 'integer', ]; /** * Eager load account with every contact. * * @var list */ protected $with = [ 'user', ]; /** * Get the account record associated with the subscription. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Account, $this> */ public function account(): BelongsTo { return $this->belongsTo(Account::class); } /** * Get the user record associated with the subscription. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User, $this> */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * Get the vault record associated with the subscription. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Vault, $this> */ public function vault(): BelongsTo { return $this->belongsTo(Vault::class); } /** * Get the local synctoken. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\SyncToken, $this> */ public function localSyncToken(): BelongsTo { return $this->belongsTo(SyncToken::class); } /** * Get the subscription's logs. * * @return \Illuminate\Database\Eloquent\Relations\MorphMany<\App\Models\Log, $this> */ public function logs(): MorphMany { return $this->morphMany(Log::class, 'loggable'); } /** * Get password. * * @return Attribute */ public function password(): Attribute { return Attribute::make( get: fn (?string $value) => decrypt($value, true), set: fn (string $value) => encrypt($value) ); } /** * Get synchronization way. * * @return Attribute */ public function isWayPush(): Attribute { return Attribute::make( get: fn (?bool $value, array $attributes) => ($attributes['sync_way'] & self::WAY_PUSH) === self::WAY_PUSH, ); } /** * Get synchronization way. * * @return Attribute */ public function isWayGet(): Attribute { return Attribute::make( get: fn (?bool $value, array $attributes) => ($attributes['sync_way'] & self::WAY_GET) === self::WAY_GET, ); } /** * Get synchronization way. * * @return Attribute */ public function isWayBoth(): Attribute { return Attribute::make( get: fn (?bool $value, array $attributes) => ($attributes['syncWay'] & self::WAY_BOTH) === self::WAY_BOTH, ); } /** * Scope a query to only include active subscriptions. */ public function scopeActive(Builder $query): Builder { return $query->where('active', 1); } /** * Get a new client. */ public function getClient(): DavClient { return app(DavClient::class) ->setBaseUri($this->uri) ->setCredentials($this->username, $this->password); } }