getMedia('cooperations') ->where('custom_properties.doc_type', 'proposal-template') ->sortByDesc('created_at') ->first(); if (! $media) { return; } $this->data['proposal_template'] = [ $media->uuid => $media->getPathRelativeToRoot(), ]; } protected function getHeaderActions(): array { return [ BackAction::make() ->url(ListCooperations::getUrl()), ]; } protected function getSavedNotification(): ?Notification { return CheerfulNotification::update(); } protected function getRedirectUrl(): string { return $this->getResource()::getUrl('index'); } protected function afterSave(): void { $record = $this->getRecord(); $data = $this->data; if (empty($data['proposal_template'])) { return; } $filePath = collect($data['proposal_template'])->first(); $fullPath = Storage::disk(config('filesystems.default'))->path($filePath); if (! file_exists($fullPath)) { return; } $record ->addMediaFromDisk($filePath, config('filesystems.default')) ->preservingOriginal() ->withCustomProperties([ 'feature' => 'cooperations', 'doc_type' => 'proposal-template', 'date' => now()->toDateString(), ]) ->toMediaCollection('cooperations'); } }