rhdelaney's avatar

Exporting filtered Data from a Search

So, I'm trying to export the data that is filtered from a search but I'm having a hard time getting this to work.(I can export all or one selected id perfectly fine). We use a variable to generate the view of the table so exporting the view would difficult would it be better to attempt to use the url's query string or is there a way to grab the old query/search? Any ideas or experience would be appreciated thank you!

0 likes
2 replies
petrit's avatar

Share you code here. Maybe somebody can help after reading your code

rhdelaney's avatar

Okay so I have an individual ones for id's, but after doing a search I want to also be able to export all the results on the page. So, this would be the function for it but all it's doing is printing all the results from the database(because I don't know how to implement the other method and that is what I'm asking for help with) basically:

public function pdfAll() {
    $users = User::select('id', 'first_name','last_name', 'email')->get();
    Excel::create('AllUsers', function($excel) use($users) {
        $excel->sheet('Sheet 1', function($sheet) use($users) {
            $sheet->fromArray($users, null, 'A1', false, false);
            $headings = array('', 'First Name','Last Name','Email');
            $sheet->prependRow(1, $headings);
            });
        })->export('pdf');
}

The view is generated with this:

return view('users.index')
    ->with(['tableData'=> $userTable->render(),
            'navData' => $navBar->render()]);

So I can't export view without "tableData" but that holds the code for the info we want to print in the table on the view-> the id's aren't there so I can't access that. Thanks to the search query we have set up for the page. Idk how much code I need to share or what code to share. I'm mainly asking for ideas on what to do. Like should I try to get the old search from a request somehow? Should I try using the query string from the search results?

Please or to participate in this conversation.