Created
October 19, 2015 11:34
-
-
Save mariano-aguero/ed7d933e4a86564ba34f to your computer and use it in GitHub Desktop.
Timestamp format trait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Models; | |
class Example extends Controller | |
{ | |
use TimestampsFormatTrait; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Models; | |
use Carbon\Carbon as Carbon; | |
use Config; | |
trait TimestampsFormatTrait | |
{ | |
public function getCreatedAtAttribute($value) | |
{ | |
return Carbon::parse($value)->toIso8601String(); | |
} | |
public function setCreatedAtAttribute($value) | |
{ | |
$this->attributes['created_at'] = Carbon::parse($value)->toDateTimeString(); | |
} | |
public function getUpdatedAtAttribute($value) | |
{ | |
return Carbon::parse($value)->toIso8601String(); | |
} | |
public function setUpdatedAtAttribute($value) | |
{ | |
$this->attributes['updated_at'] = Carbon::parse($value)->toDateTimeString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment