hasMany(BankAccount::class, 'institution_id'); } public function getEnabledConnectedBankAccounts(): Collection { return $this->connectedBankAccounts()->where('import_transactions', true)->get(); } public function connectedBankAccounts(): HasMany { return $this->hasMany(ConnectedBankAccount::class, 'institution_id'); } public function latestImport(): HasOne { return $this->hasOne(ConnectedBankAccount::class, 'institution_id')->latestOfMany('last_imported_at'); } protected function logoUrl(): Attribute { return Attribute::get(static function (mixed $value, array $attributes): ?string { if ($attributes['logo']) { return Storage::disk('public')->url($attributes['logo']); } return null; }); } public function logo(): Attribute { return Attribute::set(static function (mixed $value): ?string { if ($value) { $decoded = base64_decode($value); $filename = 'institution_logo_' . uniqid('', true) . '.png'; Storage::disk('public')->put($filename, $decoded); return $filename; } return null; }); } }