In this tutorial, we will see how to download file in laravel 8. We will see example of response download with file in laravel 8.

Firstly, create a new route as given in example below:


use App\Http\Controllers\DownloadFileController;
Route::get('/file-download', [DownloadFileController::class, 'index'])->name('');

Now add "downloadFile()" method in DownloadFileController. 



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DownloadFileController extends Controller
    public function index()
    	$filePath = public_path("dummy.pdf");
    	$headers = ['Content-Type: application/pdf'];
    	$fileName = time().'.pdf';

    	return response()->download($filePath, $fileName, $headers);

I hope this example helps you.