title: Unexpected data found. Unexpected data found. Trailing data
body: <p>I create excel import function and it working fine until I notice the date is not inserted properly, so I try to format the date like <code>Y-m-d</code> to store properly in MySql, but the carbon gives below error</p>
  <blockquote>
  <p>Carbon\Exceptions\InvalidFormatException</p>
  <p>Unexpected data found. Unexpected data found. Trailing data</p>
  </blockquote>
  <p>In excel I may have <code>d/m/Y</code> or <code>Y/m/d</code> so I want to format to tored in DB</p>
  <p>My Import code</p>
  <pre><code>public function model(array $row)
  {
      return new Staff([
          'employee_no'               =&gt; $row['id'],
          'name'                      =&gt; $row['name'],
          'address'                   =&gt; $row['address'],
          'fathers_name'              =&gt; $row['father'],
          'dob'                       =&gt; $this-&gt;transformDate($row['dob']),
          'blood_group'               =&gt; $row['blood_group'],
          'phone'                     =&gt; $row['phone'],
          'password'                  =&gt; Hash::make($row['id']),
      ]);
  }
  
  public function transformDate($value, $format = 'Y-m-d')
  {
      try {
          return \Carbon\Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value));
      } catch (\ErrorException $e) {
          return \Carbon\Carbon::createFromFormat($format, $value);
      }
  }
  </code></pre>
  <p>My Staff Model</p>
  <pre><code>class Staff extends Authenticatable
  {
    protected $fillable = [
      'name', 'employee_no', 'designation_id', 'fathers_name', 'dob', 'identification_mark', 'blood_group', 'phone', 'address', 'height', 'rfid_no', 'building_id', 'password',
    ];
  
    protected $casts = ['dob'];
  }
  </code></pre>
  <p>What is the correct way, or do I have to approach the new <code>format</code> for <code>dob</code></p>