user10139010
user10139010

Reputation:

Laravel Storage File not found

I am trying to bind a downloadable csv template to a button which will sit in storage but i keep receiving an error i have tried below but having no luck can anyone see where i am going wrong?

Download Route

Created a download route which refers to the template in storage.

public function download()
{
   return Storage::download('template.csv');
}

route file

Route::get('invites/download', 'InviteController@download')->name('invite.download');

Button

<a href="{{action('InviteController@download')}}" class="btn btn-primary mb-3">Download template</a>

Template location

storage/app/public/template.csv

Error

This is the error i keep receiving.

League \ Flysystem \ FileNotFoundException
File not found at path: template.csv

Can i get some help to see where i am going wrong?

Upvotes: 0

Views: 1168

Answers (1)

STA
STA

Reputation: 34828

You can fix the issue by simply using file_get_contents() instead :

return file_get_contents(public_path('storage/template.csv'));

This will work if you have created the symlink as well php artisan storage:link,

If you want to use storage_path, then :

return file_get_contents(storage_path('app/public/'.'template.csv'));

Upvotes: 0

Related Questions