Laravel-excel: Customize the Query dynamically when exporting from view?

Created on 16 Aug 2018  Â·  4Comments  Â·  Source: Maatwebsite/Laravel-Excel

How to customize the query when exporting from a view in 3.0? Was super easy in 2.1.

I want to change the query based on users parameters, not just use all(); but still want to export from a view so I can do custom logic with relationships.

Feels like I need a mix of fromQuery and fromView?

question

Most helpful comment

Just the same as you would for fromQuery: https://laravel-excel.maatwebsite.nl/3.0/exports/from-query.html#customizing-the-query Pass the params via the constructor and use them in view()

All 4 comments

Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/contributing) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.

You can just do your custom query in the fromView method like done in 2.1. You don't need fromQuery for that.

public function view(): View
    {
        return view('exports.invoices', [
            'invoices' => Invoice::query()->where('foo', 'bar')->get()
        ]);
    }

How do you pass arguments to it? The where needs to change based on the
route.

On Fri, Aug 17, 2018, 3:38 AM Patrick Brouwers notifications@github.com
wrote:

You can just do your custom query in the fromView method like done in
2.1. You don't need fromQuery for that.

public function view(): View { return view('exports.invoices', [ 'invoices' => Invoice::query()->where('foo', 'bar')->get() ]); }

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Maatwebsite/Laravel-Excel/issues/1765#issuecomment-413784167,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AELd8_RR8_DrRNNlzBay0q1OXHdddbD9ks5uRnMFgaJpZM4WAnr8
.

Just the same as you would for fromQuery: https://laravel-excel.maatwebsite.nl/3.0/exports/from-query.html#customizing-the-query Pass the params via the constructor and use them in view()

Was this page helpful?
0 / 5 - 0 ratings