0

I'm new to PHP and practicing with the following GitHub project: https://github.com/AshutoshChoubey/SaiAutoCare

I just want to export the numbers from the table in txt format. I got the code from a contributor, here it is:

$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)
];);

Here is the image of what I am trying to do: enter image description here

Here's the code:

<div class="col-sm-6 col-lg-3">
    <div class="card text-white bg-primary">
      <div class="card-body pb-0">
        <div class="btn-group float-right">
          <button type="button" class="btn btn-transparent dropdown-toggle p-0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="icon-settings"></i>
          </button>
          <div class="dropdown-menu dropdown-menu-right">
            <a class="dropdown-item" href="#">Export to TXT</a>
          </div>
        </div>
        <h4 class="mb-0">{{ $TotalCustomers }}</h4> 
        <p>Marketing Numbers</p>
      </div>
      <div class="chart-wrapper px-3" style="height:70px;">
        <canvas id="card-chart1" class="chart" height="70"></canvas>
      </div>
    </div>
  </div>

Here is the link to my last question: How to export a .txt file from a column of a table in MySQL database?

I just want, when user clicks the href link, it will download the file from the database.

I'm new to PHP and MySQL, that's why I'm sorry if I am not able to provide all the required information.

  • 1
    https://stackoverflow.com/questions/21923934/exporting-table-to-csv-via-php-button – Peter Jun 16 '20 at 17:54
  • Ok, I have seen the question. What I'm trying to do is add code into the controller and set the routing to href. But in this thread, he is using a simple technique to send the user to a new tab and run some PHP. – Zeeshan Toor Jun 16 '20 at 18:05

0 Answers0