In Laravel, many times we may need to create a link to download sample CSV file. So that user can download sample CSV file from our website and upload correct formatted file.
It's a very simple task and to accomplish that we need to follow following simple steps.
Step 1 :- Creating a link to download sample CSV file in our view.
{!! Html::link('admin/employee/sample-csv-download', 'Download Sample CSV', array("class" =>"btn btn-default", "style" => "")) !!}
Step 2:- Make a route configuration in your routes.php
Route::get('admin/employee/sample-csv-download', function(){
$headers = array( 'Content-Type' => 'text/csv');
return Response::download('csv/sample.csv', 'sample.csv', $headers);
});
Step 3:- Create a folder in your public directory named as csv and add a file named as sample.csv
0 Comment(s)