DcatAdmin 中,调用Grid 类的 tools() 方法增加一个添加自定义按钮,实现下载模板文件,应该如何写路径
Laravel 版本为5.8
Dcat Admin 版本为2.2.2-beta
在控制器里,新增了一个按钮
$grid->tools(function (Grid\Tools $tools) {
$tools->append(MarketExpenseTemplate::make());
});
在Actions里增加了一个Actions,
<?php
namespace App\Admin\Actions;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Actions\Response;
class MarketExpenseTemplate extends Action
{
/**
* @return string
*/
protected $title = '<button class="btn btn-outline-info"><i class="feather icon-download"></i>下载导入模板</button>';
/**
* Handle the action request.
*
* @return Response
*/
public function handle()
{
$file = 'storage/模板.xlsx';
return $this->response()->download($file);
}
}
php artisan storage:link已建立
在public目录下生成软连接,指向storage/app/public
模板文件的路径为:storage/app/public/模板.xlsx
第一种写法:
public function handle()
{
$file = '模板.xlsx';
return $this->response()->download($file);
}
提示:404 Not Found,找不到文件,浏览器路径是
admin/模板.xlsx
第二种写法:
public function handle()
{
$file = 'storage/模板.xlsx';
return $this->response()->download($file);
}
依然提示:404 Not Found,找不到文件,浏览器路径是
admin/storage/模板.xlsx
第三种写法:
public function handle()
{
$file = storage_path('模板.xlsx');
return $this->response()->download($file);
}
依然提示:404 Not Found,找不到文件,浏览器路径是
admin/home/www/dcat/storage/模板.xlsx
各位大神,帮忙指点一二。
已解决
文件存放于storage/app/public/目录下,
需建立软链接
php artisan storage:link