首页 > 解决方案 > 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?

标签: laravellaravel-storage

解决方案


您可以通过简单地使用file_get_contents()来解决问题:

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

如果您也创建了符号链接,这将起作用php artisan storage:link

如果你想使用storage_path,那么:

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

推荐阅读