all(); if (!$uploadInfoSectorialRequest->hasFile('file')) { return $this->errorResponse( false, '', 500); } $file = $uploadInfoSectorialRequest->file('file'); $data['name'] = Str::of($file->getClientOriginalName())->explode('.')->offsetGet(0); $data['uid'] = Str::of($file->hashName())->explode('.')->offsetGet(0); $extension = $file->getClientOriginalExtension(); $data['path'] = $file->storeAs('pdf', $data['uid'].".{$extension}", 's3'); return InfoSectorial::query()->create($data); } public function download() { $created_at = InfoSectorial::query()->max('created_at'); $data = InfoSectorial::query()->where('created_at', '=', $created_at)->first(); if (!Storage::disk('s3')->exists($data->path)) { return $this->errorResponse( false, '', 500); } $headers = [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="'. basename($data->path) .'"', ]; return response()->make(Storage::disk('s3')->get($data->path), 200, $headers); } }