url($this->getReportPath()); } /** * @throws Throwable */ public function __construct( private AppReport $report, private User $user, private ?string $type, ) { $this->dir = Str::uuid(); throw_unless($type, ValidationException::withMessages(['Wrong accept mime type'])); } /** * @throws Throwable */ public function handle(): void { Storage::drive(self::STORAGE_DRIVE)->makeDirectory("reports/$this->dir"); $fileName = $this->getReportPath(); $this->report->store($fileName, self::STORAGE_DRIVE, $this->type === 'pdf' ? Excel::MPDF : Str::ucfirst($this->type)); $this->user->notify((new ReportGenerated($fileName, self::STORAGE_DRIVE))); $dir = $this->dir; // dispatch( // static fn() => Storage::drive(self::STORAGE_DRIVE)->deleteDirectory("reports/$dir") // )->delay(now()->addHour()); } public function uniqueId(): string { return "{$this->user->id}_{$this->report->getReportId()}_$this->type"; } private function getReportPath(): string { return "/reports/$this->dir/{$this->report->getLocalizedReportName()}.$this->type"; } }