0

I want to export the big data (>10K) when I clicked the 'export button'. I tried to use the Yagra Datatable, however it only can export the current page for pagination. so i tried the query export Maatwebsite. What I did is when 'export' button is clicked, the result will be passed to the excel function and it will export the data into my local machine. My controller is like below:

public function filterQuery(Request $request)
{
    $dataGender = $request->dataGender;
    $ethnicity = $request->ethnicity;



What should I fix so that when I clicked the button, the query will export the result into CSV? 

1 Answer 1

0

excel() takes 2 parameters. Request $request is sent automatically, but $type is not.

function excel(Request $request, $type) { ... }

Your uri /custom doesn't have a parameter, so the only way to send type is by appending it as a GET parameter. (eg. /custom?type=some_type)

Your options:

  1. Put a default value in your excel() function.
function excel(Request $request, $type = 'default') { ... }
  1. Pass a value on your route.

<a href="{{ route('export_excel.excel') }}?type=some_type" class="btn btn-success">Export to Excel</a>

  1. Remove $type parameter.
function excel(Request $request, $type)
function excel(Request $request)
{
    return Excel::create('FILENAME', function ($excel) use ($data) {
        $excel->sheet('mySheet', function ($sheet) use ($data) {
            $sheet->fromArray($data);
        });
    })->download($type);
    })->download('default');
}
Sign up to request clarification or add additional context in comments.

5 Comments

Undefined variable: data, at excel function
I'm assuming you get your $data some way. Just define $data = ... before the return.
The problem is actually I dont really sure how to pass the $data from query filterQuery() , so the array will be exported using excel()
That's not really an error. Can't you copy the query directly?
I've copied the code, but system lag once I run. I think it query all the data from ModifiedDppr table, so thats why its slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.