laravel - 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?
解决方案
您可以通过简单地使用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'));
推荐阅读
- python - 将整数转换为时间格式
- python-3.x - Pandas 将列的所有值替换为仅一组的平均值
- javascript - hasClass 不工作。当出现“活动卡”类时,我尝试将类添加到 div 中。有任何想法吗?
- python - Python如何根据另一个csv-pandas在一个csv中搜索值?
- google-cloud-platform - 由 API 创建时电子表格的位置
- java - 将字符串从 MySQL 表读取到 Eclipse 时遇到问题
- python - Python增量迭代循环
- reporting-services - 从参数中获取先前的第一个值
- javascript - 如何动态使用react路由
- python - csv 文件 - 找出谁有最小值和最大值