title: Laravel mutate date before saving to database?
body: <p>I have a date that's being selected in a datepicker in the following format</p>
  
  <pre><code>Y-m-d g:i A
  </code></pre>
  
  <p>So using AM/PM, it shows the following in my input field, which is correct</p>
  
  <p><a href="https://i.stack.imgur.com/yj0Wz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yj0Wz.jpg" alt="enter image description here"></a></p>
  
  <p>When I submit the form offcourse Laravel won't update the record because the format is unknown to my DATETIME field in mysql.</p>
  
  <p><strong>My 'date' field is added to the $dates array so it should be parsed by Laravel</strong></p>
  
  <blockquote>
    <p>I tried using a Mutator on my Model as following, without success</p>
  </blockquote>
  
  <pre><code>public function setDateAttribute($value)
  {
      $this-&gt;attributes['date'] = Carbon::createFromFormat('Y-m-d g:i A', $value)-&gt;format('Y-m-d H:i:s');
  }
  </code></pre>
  
  <p>The original value is not being updated.
  Any idea what I might be doing wrong? </p>
  
  <p>Thank you</p>