I want to export the phone numbers in .txt format line by line. Table name is customers and the column name is customer_contact_numbers from the database saiautocare I am using the Laravel framework, JQuery and MySQL database.
When I click that button it will ask me where to save the file and export the numbers line by line into the text file.
Here's the code:
{{ $TotalCustomers }}
Marketing Numbers
I'm new to PHP and MySQL, that's why I'm sorry if I am not able to provide all the required information.
解决方案$customers = Customer::all();
$phoneNumbers = "Phone numbers \n";
foreach ($customers as $customer) {
$content .= $customer->customer_contact_numbers;
$content .= "\n";
}
// file name to download
$fileName = "contact_numbers.txt";
// make a response, with the content, a 200 response code and the headers
return Response::make($content, 200, [
'Content-type' => 'text/plain',
'Content-Disposition' => sprintf('attachment; filename="%s"', $fileName),
'Content-Length' => sizeof($content)
];);