Skip to content

Commit

Permalink
Update InteractsWithPivotTable.php
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevinruscoe committed Jan 5, 2018
1 parent 61f8477 commit a433ff8
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ protected function baseAttachRecord($id, $timed)
protected function addTimestampsToAttachment(array $record, $exists = false)
{
$fresh = $this->parent->freshTimestamp();

if ($this->using) {
$pivotModel = new $this->using;
$fresh = $fresh->format($pivotModel::getDateFormat());
}

if (! $exists && $this->hasPivotColumn($this->createdAt())) {
$record[$this->createdAt()] = $fresh;
Expand Down

0 comments on commit a433ff8

Please sign in to comment.