laravel model created at format edit

Solutions on MaxInterview for laravel model created at format edit by the best coders in the world

showing results for - "laravel model created at format edit"
Silvana
06 Jan 2021
1{{ date('d.m.Y H:i:s', strtotime($value->created_at)) }}
Aaliyah
15 Jun 2017
1//In your Post model add two accessor methods like this:
2
3public function getCreatedAtAttribute($date)
4{
5    return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d');
6}
7
8public function getUpdatedAtAttribute($date)
9{
10    return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d');
11}
12//Now every time you use these properties from your model to show a date these will be presented differently, just the date without the time, for example:
13
14$post = Post::find(1);
15echo $post->created_at; // only Y-m-d formatted date will be displayed
16//So you don't need to change the original type in the database. to change the type in your database you need to change it to Date from Timestamp and you need to do it from your migration (If your using at all) or directly into your database if you are not using migration. The timestamps() method adds these fields (using Migration) and to change these fields during the migration you need to remove the timestamps() method and use date() instead, for example:
17
18$table->date('created_at');
19$table->date('updated_at');