If you are working with images:
Route::get('/file/download', function() {
// get your filepath
$filepath = 'path/to/image/image.png';
return Response::download($filepath);
});
Then in your view:
<img src="{{url('/file/download')}}" class="rounded-circle" />
For any other file:
Route::get('/file/download', function() {
// get your filepath
$filepath = 'path/to/file/essay.docx';
return Response::download($filepath);
});
Your view:
<a href="{{url('/file/download/')}}">Download</a>
If you wish you may use a controller:
namespace MyNamespace;
use IlluminateRoutingController;
class FilesController extends Controller
{
public function downloadFile()
{
// get your filepath
$filepath = 'path/to/file/essay.docx';
return Response::download($filepath);
}
}
Then your route definition would look like:
Route::get('/file/download', ['as' => 'file.download', 'uses' => 'MyNamespaceFilesController@downloadFile']);
And your view:
<a href="{{route('file.download')}}">Download</a>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…