I have a button and when I click that button the data should be opened in csv format
public function get_textfile() {
$table = Campaign::all();
$file = fopen('file.csv', 'w');
foreach ($table as $row) {
fputcsv($file, $row);
}
fclose($file);
header("Content-type: text/csv");
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="campaign.csv"');
header("Expires: 0");
// return Redirect::to('');
}
the above code is there in my controller ...
my button is in view (i have problem in routing how to route ?)
<a href= {{ URL::to('?????' ); }} "" class="btn btn-large btn-success">Export CSV file</a>
Can anyone please do explain the process ?