0
votes

I developed a Laravel application that connects to a external MySQL database for reports. I'm using Maatwebsite/Laravel-Excel 3.1 to be able to export to excel.

In this app, I have a method in my model that uses Input::get() for 3 variables ($from, $to, $paymentType). This method is called whenever the user chooses date range and payment type as filter for their reports. Everything works as it should since data is displayed in my view.

Now this same method is called when the user chooses to export the file to excel. Again, all that works except the files is blank.

The curious thing is that if I replace all Input::get() for static values such as '2018-11-14' for the dates and 'n' for payment type, then the file exports with data.

I've been struggling with this for a couple of days so I hope someone can help me.

Thanks,

Ernesto

2
What version of Laravel are you using? Input::get() is deprecated and you should use $request->input() instead.hktang
Sorry, I'm using Laravel 5.6. When I use $request->input() I get Call to undefined method Illuminate\Database\Eloquent\Builder::input().orpheus779
Which format are you trying to create e.g. csv, xls, or xlsx? Also are you creating exporting excel file from view, from collection or from array. Can you please add your part of the code (from controller) where you are exporting it and/or any other relevant source snippet. This will help to identify the cause.Muhammad Sheraz

2 Answers

0
votes

First, towards the top of the controller file, add:

use Illuminate\Http\Request;

Then, you can access the fields by:

$request->input('from');
$request->input('to');

Assumption: from and to are correct field names.

You can also use request()->input('from') etc. directly (note the absence of $).

Please see this for more info: https://laravel.com/docs/5.6/requests

0
votes

If the parameters are obtained from the request you should use $request->input() instead of Input::get().

If used in a function where $request is not available you could use request('variable') to get the variable value from the request.