Add ability to specify the file name with a method when using the Exportable concern #4116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides a way to define the file name to be used by the Exportable concern with a method (instead of an attribute).
1️⃣ Why should it be added? What are the benefits of this change?
Currently, it is possible to set a file name to be used by the Exportable trait, by setting a
$fileName
attribute.In my experience, however, the name of the file usually depends on some attribute of the export class: e.g., I might want to export all the articles in a year, and call the file "articles2024.csv". I cannot currently do that unless I specify the file name in each method call (e.g.,
(new ArticlesExport)->download('articles2024.xlsx')
), which is not ideal since it results in duplication if it needs to be done in different places.2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No.
3️⃣ Does it include tests, if possible?
Yes.
4️⃣ Any drawbacks? Possible breaking changes?
No breaking changes: if the
getFileName()
method is not present, it will fall back to the$fileName
attribute.5️⃣ Mark the following tasks as done:
6️⃣ Thanks for contributing! 🙌
My pleasure!
If you believe that it would be more in line to this package's style to have a
WithFileName
interface to identify when thegetFileName()
method should be use, I can rewrite it in this way.