title: Export .xslx data using Laravel Excel with parameter
body: <p>I want to export data from the database to .xlsx using Laravel-Excel.
  I want to pass three parameters to query the data and download into excel file.
  I already search and read a few examples but still failed to make the excel file to download.</p>
  
  <p>This is my blade file. </p>
  
  <pre><code>@section('content')
  &lt;div class="container"&gt;
      &lt;div class="row justify-content-center"&gt;
          &lt;div class="col-md-3"&gt;&lt;/div&gt;
          &lt;div class="col-md-6"&gt;
              &lt;div class="card"&gt;
                  &lt;div class="card-header"&gt;Download Report&lt;/div&gt;
                  &lt;div class="card-body"&gt;
                      &lt;div class="col-md-12" style="margin-bottom:15px"&gt;
                          &lt;select class="form-control" name="plant" id="plant"&gt;
                              &lt;option selected value="All"&gt;Please Select Plant&lt;/option&gt;
                              @foreach($plants as $plant)
                              &lt;option value="{{ $plant-&gt;id }}"&gt;{{ $plant-&gt;name }}&lt;/option&gt;
                              @endforeach
                          &lt;/select&gt;
                      &lt;/div&gt;
                      &lt;div class="col-md-12" style=""&gt;
                      &lt;div class="input-group input-daterange" align="center"&gt;
                          &lt;input type="text" name="from_date" id="from_date" readonly class="form-control" value="&lt;?php echo date("Y-m-d");?&gt;" /&gt;
                          &lt;div class="input-group-addon" &gt;To&lt;/div&gt;
                          &lt;input type="text"  name="to_date" id="to_date" readonly class="form-control" value="&lt;?php echo date("Y-m-d");?&gt;"/&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;br&gt;
                      &lt;div class="col-md-12" align="center"&gt;
                          &lt;button type="button" name="search" id="search" class="btn btn-info btn-block"&gt;Download&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col-md-3"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;script type="text/javascript"&gt;
  
      $(function() {
  
              var date = new Date();
  
              $('.input-daterange').datepicker({
              todayBtn: 'linked',
              format: 'yyyy-mm-dd',
              autoclose: true
              });
  
              $.ajaxSetup({
                  headers: {
                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                  }
            });
  
            $('#search').click(function(e){
              e.preventDefault();
              var from_date = $('#from_date').val();
              var to_date = $('#to_date').val();
              var plant = $('#plant').val();
                  if(plant != 'All')
                  {
                      $.ajax({
                          url:"{{ route('export') }}",
                          data:{from_date:from_date, to_date:to_date, plant:plant},
                          dataType:"json",
                      })
                  }
                  else
                  {
                      alert('Please Select Plant');
                  }
              });
  
          });
  
        &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>This is my function at the controller</p>
  
  <pre><code>    public function export(Request $request)
      {
          return (new DetailReportDownload($request-&gt;plant,$request-&gt;from_date,$request-&gt;to_date))-&gt;download('Report Details.xlsx');
      }
  </code></pre>
  
  <p>and This is my Export file</p>
  
  <pre><code>class DetailReportDownload implements FromQuery, WithHeadings
  {
      use Exportable;
  
      protected $plant,$from,$to;
  
      public function __construct(String  $from,String $to,String $plant)
      {
          $this-&gt;plant = $plant;
          $this-&gt;from = $from;
          $this-&gt;to = $to;
      }
  
      public function headings(): array
      {
          return [
              'plandate',
              'workcentre',
              'partno',
              'prodduration',
              'totaldowntime',
              'planout',
              'cumout',
          ];
      }
  
      public function query()
      {
          return  DB::table('plannings')
          -&gt;select(DB::raw('plandate, workcentre, partno, prodduration, coalesce(sum(downduration),0) as totaldowntime, planout, cumout'))
          -&gt;join('prodstatuses', 'plannings.id', '=', 'prodstatuses.id')
          -&gt;leftJoin('downtimes', 'plannings.id', '=', 'downtimes.plan_id')
          -&gt;whereBetween('plandate', array($this-&gt;from, $this-&gt;to))
          -&gt;where('plant_id',$this-&gt;plant)
          -&gt;where('status','Finished')
          -&gt;groupBy('plannings.id')
          -&gt;orderBy('plannings.id');
      }
  }
  </code></pre>
  
  <p>I wanted to download excel file from parameter given in blade file.
  Thanks in advance for any help</p>