Laravel下载不起作用

Laravel下载不起作用

问题描述:

I'm trying to trying to download data but for some reason it doesn't work

view

@foreach($files as $file)

  {!! Html::link('public/'.$file->name, $file->name) !!}

@endforeach

controller

public function download($file_name){
    $file_path = public_path('/'.$file_name);
    return response()->download($file_path);
}

route

Route::get('download/{file}','FilesController@download');

I get this error

NotFoundHttpException in RouteCollection.php line 161

in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691

The path is wrong, you are observing /download/{file} but calling /public/{file}.

{!! Html::link('download/'.$file->name, $file->name) !!}