*/ use HasFactory, HasUuids; /** * The broad "use AI to help understand your finances" consent scope. */ public const SCOPE_FINANCE = 'finance'; protected $fillable = [ 'user_id', 'scope', 'version', 'accepted_at', 'revoked_at', ]; protected function casts(): array { return [ 'accepted_at' => 'datetime', 'revoked_at' => 'datetime', ]; } /** @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * Scope to consents that are currently active for the given scope and the * current consent version (un-revoked and matching the live copy version). * * @param Builder $query * @return Builder */ public function scopeActive(Builder $query, string $scope = self::SCOPE_FINANCE): Builder { return $query ->where('scope', $scope) ->where('version', (string) config('ai_suggestions.consent_version')) ->whereNull('revoked_at'); } }