Answer the question
In order to leave comments, you need to log in
How to work with date in Laravel?
Previously, in Laravel, all dates were stored as a simple number (received through the time() function). Now you need to use the standard means of getting the date in Lara.
In Lara, by default, when creating a record in the database, the "created_at" column is used, which uses the "timestamp" type.
How can I get the date in the format I need?
PS: used to be: "date('dmY H:i:s')".
Answer the question
In order to leave comments, you need to log in
In Laravel, the Model has a protected $dates variable.
All database fields written to this variable are automatically converted to a Carbon\Carbon instance, and then you can work with them simply:
<?php
class MyModel extends Model {
protected $dates = ['signed_at'];
}
// ....
$model = MyModel::first();
echo $model->signed_at->format('d.m.Y H:i:s');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question