Laravel Delete File After Download Response Example

By Hardik Savani November 4, 2022 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 and laravel 9 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 :