-
Notifications
You must be signed in to change notification settings - Fork 11.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
[5.5] Ensure Pivot models $dateFormat is used when creating a pivot record. #22656
Conversation
As with #22484 , when inserting a pivot record via `->attach()` the `InteractsWithPivotTable.php` trait doesn't check to see if the pivot table has a model representation. It' simply finds the table name and inserts a new record. Because of this, the timestamps are passed as `Carbon` instances and then turn to strings via its `toString()` method. If the consumer is using a pivot Model, it should use that models dateFormat to format by, not the `toString()` method. This simply news-up the pivot model, fetches it's dateformat and formats the `$fresh` date against it.
...actually, hold fire with this. |
This won't actually fix the issue above, it does fix some sort of issue ;), in that the |
So it doesn't fix the issue you link? Need more information and explanation before merging. |
It's fixes part of the issue above, but the actual issue it fixes is as follows. When using the This PR basically checks to see if the Pivot model has a |
This sounds like something that should have tests. |
@sisve indeed. |
@kevdotbadger You are calling |
I put this in 5.6 since it required a breaking change to method visibility of getDateFormat. I also added a test. |
I'm having this issue in Laravel 9 ! I have precision 6 on the timestamps and also the option |
the issue seams to be fixed by adding the namespace Illuminate\Database;
|
As with #22484 , when inserting a pivot record via
->attach()
theInteractsWithPivotTable.php
trait doesn't check to see if the pivot table has a model representation. It' simply finds the table name and inserts a new record. Because of this, the timestamps are passed asCarbon
instances and then turn to strings via itstoString()
method. If the consumer is using a pivot Model, it should use that models dateFormat to format by, not thetoString()
method. This simply news-up the pivot model, fetches it's dateformat and formats the$fresh
date against it.