Laravel Delete File After Download Response Example

By Hardik Savani April 16, 2024 Category : Laravel

Hi,

In this quick example, let's see laravel delete file after download. I would like to show you delete file after download laravel. you will learn delete after download laravel. you can see how to delete file after download in laravel.

you can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

Laravel provides deleteFileAfterSend() method to remove file after download. i will give you simple example, we will response download pdf file and then it will delete file automatically. I hope you will find your solution.

Example:

<?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);

}

}

I hope it can help you...

Tags :
Shares