How to convert a carbon into string, to take the date only?
i prefere this
$model_item->created_at->toDateString();
since all date fields that located in protected $dates array
in the modal is type of \Carbon\Carbon
.
so the above code could apply to any date field as long as you declared it as date in $dates array
in the modal
as follow
// this includes created_at and updated_at by default so no need to add it
protected $dates = ['approved', 'seen_at'];
$collection_item->created_at->format('Y-m-d');
It is also possible to add automatic casting to your model, for example :
protected $casts = [
'created_at' => 'date:Y-m-d',
'updated_at' => 'datetime:Y-m-d H:00',
];
Remark : your mileage may vary depending on your Laravel version
https://laravel.com/docs/8.x/eloquent-mutators#date-casting
https://laravel.com/docs/8.x/eloquent-serialization#date-serialization