title: How to download file excel from jquery and route have post method - laravel excel
body: <p>I wanna ask something about export excel using laravel and some plugin <code>maatwebsite/excel</code>, everything is ok when I through the normal tutorial and like a normal people is working without error, but my problem is when I try make a custom query to my <code>ExampleExport.php (not real)</code> and the result of my excel file is not downloading, I see my result on my console, is doesnt showing anything error, but when I click in network tab and click again to my url the error message show like this :</p>
  <pre><code>The GET method is not supported for this route. Supported methods: POST.
  </code></pre>
  <p>anyway my error is normal when you try accessing <code>post</code> method and that error will be show, but is it have another way to solve my problem, so that I can download my excel file? I hope there's any way to make my problem solve, well I wanna put my code in below so that everyone can know what the problem that I have, thank you before, have a nice day</p>
  <p><strong>JQUERY :</strong></p>
  <pre><code> // export excel button click
   $(&quot;#export_excel&quot;).on('click', function () {
        const yearInput = $(&quot;#year_input&quot;).val();
        // get api data only yearInput
        $.ajax({
             url: `report-payment/filter-data/year_result=${yearInput}`,
             method: &quot;GET&quot;,
             data: {
                  yearInput: yearInput
             },
             success: function (success) {
                  *...* &lt;= I skip this code
                   $.ajax({
                       url: `report-payment/export-excel`,
                       type: &quot;POST&quot;,
                       dataType: &quot;json&quot;,
                       data: {
                            nameOccupant: infoNameOccupant,
                            roomOccupant: infoRoomOccupant,
                            locationRoomOccupant: infoLocationRoomOccupant,
                            infoPayment: infoPayment
                       },
                       success: function (success) {
                            if (success) {
                                 console.log('success');
                            }
                       }
                  });
             }
         });
     });
  </code></pre>
  <p><strong>CONTROLLER :</strong></p>
  <pre><code>public function paymentExportExcel(Request $filter)
  {
      $get_name_occupant = $filter-&gt;nameOccupant;
      $get_room_occupant = $filter-&gt;roomOccupant;
      $get_location_room_occupant = $filter-&gt;locationRoomOccupant;
      $get_info_payment = $filter-&gt;infoPayment;
  
      return Excel::download(new PaymentExport($get_name_occupant, $get_room_occupant, $get_location_room_occupant, $get_info_payment), 'report-payment.xlsx');
  }
  </code></pre>
  <p><strong>FILE EXPORT :</strong></p>
  <pre><code>public function collection()
  {
      for ($payment = 0; $payment &lt; count($this-&gt;info_payment); $payment++) { 
          $raw_info_payment[] = [
              'info_payment' =&gt; $this-&gt;info_payment[$payment]
          ];
      }
  
      for ($payment = 0; $payment &lt; count($raw_info_payment); $payment++) { 
          $get_arr_info_payment[] = \array_map(function ($value) {
              return $value == &quot;-1&quot; || $value == &quot;-&quot; ? &quot;Belum Lunas&quot; : $value;
          }, $raw_info_payment[$payment]['info_payment']);
      }
  
      // make a new object to insert a new data
      for ($data = 0; $data &lt; count($this-&gt;name_occupant); $data++) { 
          $data_info_payment[] = [
              &quot;name_occupant&quot; =&gt; $this-&gt;name_occupant[$data],
              &quot;room_occupant&quot; =&gt; $this-&gt;room_occupant[$data],
              &quot;location_room_occupant&quot; =&gt; $this-&gt;location_room_occupant[$data],
              &quot;info_payment&quot; =&gt; $this-&gt;info_payment[$data]
          ];
      }
  
      return collect($data_info_payment);
  }
  </code></pre>