Answer the question
In order to leave comments, you need to log in
How to change date format in Laravel model?
The Laravel documentation says about the model property $dateFormat that this property determines how date attributes are stored in the database.
I use this property like this because I want only the date to be stored, not the time. But as a result, working with the date becomes impossible, i.e. even with a simple output it gives an errorprotected $dateFormat = 'Y-m-d'
$model->created_at
Trailing data {"exception":"[object] (InvalidArgumentException(code: 0): Trailing data at ...\www\\vendor\
esbot\\carbon\\src\\Carbon\\Carbon.php:910)...
Answer the question
In order to leave comments, you need to log in
Question: why change the date entered into the database, if it is enough to change its presentation in appearance?
There is such an option - add to the model
protected $casts = [
'created_at' => 'datetime:d/m/Y', // Свой формат
'updated_at' => 'datetime:d/m/Y',
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question