Maatwebsite/Laravel-Excel exports blank excel when using Input::get() in model
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
laravel laravel-excel
add a comment |
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
laravel laravel-excel
1
What version of Laravel are you using?Input::get()
is deprecated and you should use$request->input()
instead.
– hktang
Nov 14 '18 at 14:01
Sorry, I'm using Laravel 5.6. When I use$request->input()
I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:44
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
Nov 28 '18 at 12:04
add a comment |
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
laravel laravel-excel
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
laravel laravel-excel
laravel laravel-excel
asked Nov 14 '18 at 13:38
orpheus779orpheus779
1
1
1
What version of Laravel are you using?Input::get()
is deprecated and you should use$request->input()
instead.
– hktang
Nov 14 '18 at 14:01
Sorry, I'm using Laravel 5.6. When I use$request->input()
I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:44
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
Nov 28 '18 at 12:04
add a comment |
1
What version of Laravel are you using?Input::get()
is deprecated and you should use$request->input()
instead.
– hktang
Nov 14 '18 at 14:01
Sorry, I'm using Laravel 5.6. When I use$request->input()
I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:44
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
Nov 28 '18 at 12:04
1
1
What version of Laravel are you using?
Input::get()
is deprecated and you should use $request->input()
instead.– hktang
Nov 14 '18 at 14:01
What version of Laravel are you using?
Input::get()
is deprecated and you should use $request->input()
instead.– hktang
Nov 14 '18 at 14:01
Sorry, I'm using Laravel 5.6. When I use
$request->input()
I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().– orpheus779
Nov 14 '18 at 14:44
Sorry, I'm using Laravel 5.6. When I use
$request->input()
I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().– orpheus779
Nov 14 '18 at 14:44
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
Nov 28 '18 at 12:04
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
Nov 28 '18 at 12:04
add a comment |
2 Answers
2
active
oldest
votes
First, towards the top of the controller file, add:
use IlluminateHttpRequest;
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
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
add a comment |
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.
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301568%2fmaatwebsite-laravel-excel-exports-blank-excel-when-using-inputget-in-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, towards the top of the controller file, add:
use IlluminateHttpRequest;
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
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
add a comment |
First, towards the top of the controller file, add:
use IlluminateHttpRequest;
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
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
add a comment |
First, towards the top of the controller file, add:
use IlluminateHttpRequest;
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
First, towards the top of the controller file, add:
use IlluminateHttpRequest;
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
answered Nov 14 '18 at 14:48
hktanghktang
9391429
9391429
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
add a comment |
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
"You can also use request()->input('from') etc. directly (note the absence of $). " This works but in the same way Input::get(). Meaning it shows all the data in my view but the exported excel is blank. Forgot to mention that I did a dd($from, $to, $paymentType) to make sure the correct values are passed and sure enough they are.
– orpheus779
Nov 14 '18 at 14:57
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
@orpheus779 I see. Could you show us the relevant controller and view codes?
– hktang
Nov 15 '18 at 0:12
add a comment |
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.
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
|
show 4 more comments
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.
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
|
show 4 more comments
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.
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.
edited Nov 14 '18 at 15:06
answered Nov 14 '18 at 14:32
Adrian Hernandez-LopezAdrian Hernandez-Lopez
418213
418213
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
|
show 4 more comments
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
When I use $request->input() I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().
– orpheus779
Nov 14 '18 at 14:47
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
Where are you using the code: controller, model, repository....? Could you provide the code in your questions?
– Adrian Hernandez-Lopez
Nov 14 '18 at 14:49
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
It's being used in model. I could try to post my code but have to edit it to hide table names, etc.
– orpheus779
Nov 14 '18 at 15:00
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
See my updated answer.
– Adrian Hernandez-Lopez
Nov 14 '18 at 15:06
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>
class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
I get the same result, blank excel. Could it be an issue with the Export model instead? I have this in mi export model: <br>
class ReportsExport implements FromQuery, WithMapping, WithHeadings, ShouldAutoSize, WithColumnFormatting { /** * @return IlluminateSupportCollection */ public function query() return Report::docs()->orderBy('desc_doc');
– orpheus779
Nov 14 '18 at 15:10
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301568%2fmaatwebsite-laravel-excel-exports-blank-excel-when-using-inputget-in-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What version of Laravel are you using?
Input::get()
is deprecated and you should use$request->input()
instead.– hktang
Nov 14 '18 at 14:01
Sorry, I'm using Laravel 5.6. When I use
$request->input()
I get Call to undefined method IlluminateDatabaseEloquentBuilder::input().– orpheus779
Nov 14 '18 at 14:44
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
Nov 28 '18 at 12:04