How to stream download data from current view in Laravel 5.7











up vote
0
down vote

favorite












I am making a basic database application that allows users to submit search parameters through a form and have the results displayed in a view. I create a query from an Eloquent model, paginate, and then send the results to a view.



I would like to place a link on the results view that lets users download the results of their query in a csv file, but stream the data rather than create a file and then serve it. My problem is that I don't know how to pass the query from the results page through a route to another controller that handles the download.



The information I have found about sending data to a route involves sending parameters for a url which I am not sure helps me.



I was thinking I could cache the results by sending the data from the controller handling the query to the controller handling the download before sending it to a view, but I am not sure how to accomplish this or if Laravel provides a better way to do what I want.










share|improve this question






















  • Are you using a specific excel library, like maatwebsite/excel? They often have a method for downloading csv files from memory. Otherwise there is response()->streamDownload() if you're generating it yourself on the fly.
    – Travis Britz
    Nov 8 at 2:51












  • I am not using any libraries. I know about response()->streamDownload() but I don't know how I can do that from within a view.
    – Registered User
    Nov 11 at 0:54

















up vote
0
down vote

favorite












I am making a basic database application that allows users to submit search parameters through a form and have the results displayed in a view. I create a query from an Eloquent model, paginate, and then send the results to a view.



I would like to place a link on the results view that lets users download the results of their query in a csv file, but stream the data rather than create a file and then serve it. My problem is that I don't know how to pass the query from the results page through a route to another controller that handles the download.



The information I have found about sending data to a route involves sending parameters for a url which I am not sure helps me.



I was thinking I could cache the results by sending the data from the controller handling the query to the controller handling the download before sending it to a view, but I am not sure how to accomplish this or if Laravel provides a better way to do what I want.










share|improve this question






















  • Are you using a specific excel library, like maatwebsite/excel? They often have a method for downloading csv files from memory. Otherwise there is response()->streamDownload() if you're generating it yourself on the fly.
    – Travis Britz
    Nov 8 at 2:51












  • I am not using any libraries. I know about response()->streamDownload() but I don't know how I can do that from within a view.
    – Registered User
    Nov 11 at 0:54















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am making a basic database application that allows users to submit search parameters through a form and have the results displayed in a view. I create a query from an Eloquent model, paginate, and then send the results to a view.



I would like to place a link on the results view that lets users download the results of their query in a csv file, but stream the data rather than create a file and then serve it. My problem is that I don't know how to pass the query from the results page through a route to another controller that handles the download.



The information I have found about sending data to a route involves sending parameters for a url which I am not sure helps me.



I was thinking I could cache the results by sending the data from the controller handling the query to the controller handling the download before sending it to a view, but I am not sure how to accomplish this or if Laravel provides a better way to do what I want.










share|improve this question













I am making a basic database application that allows users to submit search parameters through a form and have the results displayed in a view. I create a query from an Eloquent model, paginate, and then send the results to a view.



I would like to place a link on the results view that lets users download the results of their query in a csv file, but stream the data rather than create a file and then serve it. My problem is that I don't know how to pass the query from the results page through a route to another controller that handles the download.



The information I have found about sending data to a route involves sending parameters for a url which I am not sure helps me.



I was thinking I could cache the results by sending the data from the controller handling the query to the controller handling the download before sending it to a view, but I am not sure how to accomplish this or if Laravel provides a better way to do what I want.







php laravel-5.7






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 19:10









Registered User

234




234












  • Are you using a specific excel library, like maatwebsite/excel? They often have a method for downloading csv files from memory. Otherwise there is response()->streamDownload() if you're generating it yourself on the fly.
    – Travis Britz
    Nov 8 at 2:51












  • I am not using any libraries. I know about response()->streamDownload() but I don't know how I can do that from within a view.
    – Registered User
    Nov 11 at 0:54




















  • Are you using a specific excel library, like maatwebsite/excel? They often have a method for downloading csv files from memory. Otherwise there is response()->streamDownload() if you're generating it yourself on the fly.
    – Travis Britz
    Nov 8 at 2:51












  • I am not using any libraries. I know about response()->streamDownload() but I don't know how I can do that from within a view.
    – Registered User
    Nov 11 at 0:54


















Are you using a specific excel library, like maatwebsite/excel? They often have a method for downloading csv files from memory. Otherwise there is response()->streamDownload() if you're generating it yourself on the fly.
– Travis Britz
Nov 8 at 2:51






Are you using a specific excel library, like maatwebsite/excel? They often have a method for downloading csv files from memory. Otherwise there is response()->streamDownload() if you're generating it yourself on the fly.
– Travis Britz
Nov 8 at 2:51














I am not using any libraries. I know about response()->streamDownload() but I don't know how I can do that from within a view.
– Registered User
Nov 11 at 0:54






I am not using any libraries. I know about response()->streamDownload() but I don't know how I can do that from within a view.
– Registered User
Nov 11 at 0:54



















active

oldest

votes











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',
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53196215%2fhow-to-stream-download-data-from-current-view-in-laravel-5-7%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53196215%2fhow-to-stream-download-data-from-current-view-in-laravel-5-7%23new-answer', 'question_page');
}
);

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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini