-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix ToCollection example #52
Conversation
As revealed in #1980 and #1999 if any parsing/processing of records is desired when using ToCollection, it must be done via model properties, because all of the results of the `collection(Collection $row)` call are ignored otherwise. The previous example with a foreach loop never did anything with the data, so the loop was pointless.
Hey @drbyte thanks for the PR. The example in the docs is correct; that's how it is intended to be used. The loop isn't pointless, as the data gets inserted into the database. By design the I'm okay with adding the example of storing the collection data into a class property, but it shouldn't replace the example that is currently in the documentation; as that's the correct way of using |
@patrickbrouwers I'm still confused then. You said "The loop isn't pointless, as the data gets inserted into the database. " ... But isn't the whole point of ToCollection that it DOESN'T insert into the database, since that's what ToModel is for. |
@drbyte no, it's isn't. The point of ToCollection is that you can handle the persistence yourself; eloquent or any other persistence layer; for instance if you have more complicated eloquent relations. |
I see. I'll close this PR as I think I need to find time to use this feature more before I can contribute to improving its clarity. Thanks for the interaction. And thanks for this great package! (I've used it more for exporting, just new to using it for importing.) |
@drbyte I'm considering allowing to combine
|
@patrickbrouwers That would be great. I think that would make the actual operation match closer to (what I initially perceived, and wanted, to be) the semantic intention according to method name. Thanks! Added: Could it be made to also support the |
Yes behind the scenes it's all the same |
👍 |
As revealed in SpartnerNL/Laravel-Excel#1980 and SpartnerNL/Laravel-Excel#1999 if any parsing/processing of records is desired when using ToCollection, it must be done via model properties, because all of the results of the
collection(Collection $row)
call are ignored otherwise.The previous example with a foreach loop never did anything with the data, so the loop was pointless.