title: How to change date format of timestamps on pivot in Laravel?
body: <p>I'm trying to change the date type of timestamps (created_at, updated_at, deleted_at) globally in the whole application from <code>timestams</code> to <code>timestampsTz</code>. In migrations it's no problem. In single models either, since I can overwrite the <code>$dateFormat</code> parameter of the model.</p>
  
  <p>But I have problem with pivot tables containing timestamps, because they don't inherit any parameters from my models.</p>
  
  <p>Let's say I have a <strong>products</strong> and <strong>attributes</strong> table with <strong>attribute_product</strong> pivot between them containing columns like <code>value</code> and <code>timestamps</code>. If I try to retrieve all attributes with values and timestamps of a product I would do something like this: <code>$product-&gt;attributes</code> but I get the error:</p>
  
  <pre><code>local.ERROR: Trailing data {"exception":"[object] (InvalidArgumentException(code: 0): Trailing data at \\vendor\\esbot\\carbon\\src\\Carbon\\Carbon.php:910)
  [stacktrace]
  #0 \\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(716): Carbon\\Carbon::createFromFormat('Y-m-d H:i:s', '2019-06-25 16:1...')
  #1 \\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(739): Illuminate\\Database\\Eloquent\\Model-&gt;asDateTime('2019-06-25 16:1...')
  #2 \\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(532): Illuminate\\Database\\Eloquent\\Model-&gt;fromDateTime('2019-06-25 16:1...')
  #3 \\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(230): Illuminate\\Database\\Eloquent\\Model-&gt;setAttribute('created_at', '2019-06-25 16:1...')
  #4 \\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(248): Illuminate\\Database\\Eloquent\\Model-&gt;fill(Array)
  ...
  </code></pre>
  
  <p>The builder retrieves the timestamp in the correct format (e.g. "2019-06-25 16:17:01+02") but when it tryes to hydrate the related models pivot data, it uses the wrong format "Y-m-d H:i:s" and fails.</p>
  
  <p>Is there any proper way to achieve this? Or is there any usable workaround?</p>
  
  <p>Any help appreciated? Thanks in advance!</p>