I have problem with update the model data in laravel 5.6, After many time I find that actually problem is with created_at and updated_at. My code:
$editStuState = StuAtt::where('studentId' , '=' , 1007)->first();
dd($editStuState -> created_at);
and dd($editStuState)
StuAtt {#382 ▼
  #table: "stu_attendance"
  #connection: "mysql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:7 [▼
    "id" => "3"
    "studentId" => "1007"
    "present" => "7"
    "absent" => "2"
    "leave" => "6"
    "created_at" => "2018-04-19 07:01:19.929554"
    "updated_at" => "2018-04-19 02:31:19.000000"
  ]
  #original: array:7 [▼
    "id" => "3"
    "studentId" => "1007"
    "present" => "7"
    "absent" => "2"
    "leave" => "6"
    "created_at" => "2018-04-19 07:01:19.929554"
    "updated_at" => "2018-04-19 02:31:19.000000"
  ]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▶]
}
Error that appears when I print the created_at field:
InvalidArgumentException
Trailing data
Where is mistake and how fix it?
Trailing data is a Carbon error, it's because you probably use PostgreSQL, and DB's date returns milliseconds.
"created_at" => "2018-04-19 07:01:19.929554"
You can add the following method to your (base) model.
    // ...
    public function getDateFormat()
    {
         return 'Y-m-d H:i:s.u';
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With