How To Download Image Or File In Laravel 9

Hello Artisan,

In this tutorial, I will show you how to download images or files in Laravel 9. In this section, I will see how to download Laravel 9. There is two way you can download the image in Laravel 9. First, you can use HTML download Attribute. Second, you can use the Laravel download method.

There is a helper called response()->download() function, using that, we can easily download files in Laravel. See the below example to understand:

 

public function downloadImage(Image $image)
{
    $imagePath = Storage::url($image->image);

    return response()->download(public_path($imagePath));
}

 

Read also: Laravel 9 Repository Design Pattern Example Tutorial

 

Hope it can help you.

 

#laravel #laravel-9x