Hello Geek, In this quick example, we’ll see how to delete File After Download Response in Laravel Example. I’d like to demonstrate how to delete a file after download Response in Laravel. You can learn how to delete a file after it has been downloaded in Laravel.This example works with Laravel 6, Laravel 7, Laravel 8, and Laravel 9.To remove a file after it has been downloaded, Laravel provides the deleteFileAfterSend() method.
I’ll give you a simple example: we’ll respond by downloading a pdf file, and the file will be deleted automatically. I hope this will help you.
Example 1:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class DemoController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
return response()
->download(storage_path('app/public/output.pdf'))
->deleteFileAfterSend(true);
}
}
All the best nerd.