'Deleting file after download s3 bucket in laravel 8

I'm creating a application that lets a user download a file. After the download I want the file to be deleted from s3 bucket. The end of my code is like this:

return response()->download(Storage::disk('cloud')->url('pdf/'.$name), $name)->deleteFileAfterSend(true);

or

$response = Storage::disk('cloud')->download('pdf/'.$name, $name);
Storage::disk('cloud')->delete('pdf/'.$name);

return $response;

None of these solutions are work. Can someone please help me to fix this issue ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source