我正在尝试创建一条路径,该路径可让我在指定路径的情况下下载文件:
example.com/download/dogs/beagles/stickypaw.jpg
example.com/download/dogs/germanshepards/woofer.jpg
example.com/download/dogs/alldogs.jpg
通常我会使用命名参数, 但是在这种情况下,这意味着要拥有3条不同的路线:
Route::get('/download/package}/{folder}/{filename}',function ($package, $folder,$filePath) {
$filePath = "$package/$folder/$filePath";
return Storage::download($filePath);
});
Route::get('/download/{package?}/{filename}', function ($package, $filePath) {
$filePath = "$package/$filePath";
return Storage::download($filePath);
});
Route::get('/download/{filename}', function ($filename) {
return Storage::download($filename);
});
下载变量后是否有获取路径的方法?
示例:
Route::get('/download/{path}', function ($path) {
// loop over the path array
});
答案 0 :(得分:1)
未经测试,但应该可以工作:
Route::get('/download/{path}', function ($path) {
$folders = explode('/', $path);
// ...
})
->where('path', '(.+)');