I recently update my laravel 8 and It seems like Carbon or date request is not working properly I am getting the following error while saving the record with date time
exception: "Error"
file: "/../vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php"
line: 848
message: "Call to undefined method DateTime::set()"
Controller
$startDate = $request->start_date_time;
$events->start_date_time = Carbon::parse($startDate);
Parsing string:
2021-07-14T07:43:27.498Z
Version
PHP 7.4.21, Laravel 8
2
Answers
Its resolved by changing my event model
Before
After
The issue is with casts
so it should be
Ref:https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting