Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper for quickly exporting without creating export for a model #4084

Closed
wants to merge 3 commits into from

Conversation

skills-up
Copy link

1️⃣ Why should it be added? What are the benefits of this change?
Allows to quickly export from a controller without creating the export specific to a model/query. E.g.,

$query = Comment::with('post')->where('user_id', auth()->user()->id);
$headings = [
  'post.title' => 'Post Name',
  'content' => 'Comment',
  'created_at' => 'Date/Time',
];
return Excel::download(
  new GenericQueryExport($query, $headings),
  'activities.csv',
  \Maatwebsite\Excel\Excel::CSV
);

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No

3️⃣ Does it include tests, if possible?
No

4️⃣ Any drawbacks? Possible breaking changes?
Makes assumptions about relations already included in the query, and single header row

5️⃣ Mark the following tasks as done:

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression.

6️⃣ Thanks for contributing! 🙌

@patrickbrouwers
Copy link
Member

Hey, thanks for your PR. Unfortunatly this is not something I'm looking for to merge.

We already have a shortcut to quickly export queries, by doing the macro:

User::query()->downloadExcel('query-download.xlsx', Excel::XLSX, true);

@skills-up
Copy link
Author

Wouldn't your way still require an export to be defined specifically for the query?
Otherwise, User::query()->downloadExcel() would result in:

BadMethodCallException  Call to undefined method Illuminate\Database\Eloquent\Builder::downloadExcel(

@patrickbrouwers
Copy link
Member

Sorry I forgot I hadn't tagged that release yet. It's part of 5.1.53 version

@skills-up
Copy link
Author

Perhaps docs need to be updated for the same.

@patrickbrouwers
Copy link
Member

patrickbrouwers commented Feb 7, 2024

Docs are updated. Perhaps PWA cache why it doesn't show up yet: https://docs.laravel-excel.com/3.1/exports/from-query.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants