1

I am storing created_at and updated_at as unix timestamp

for that i add following line to my modal its working fine.

class Test extends Model
{
    protected $dateFormat = 'U';

    protected $fillable = [
        'user_id','question_id','answer',
    ];
}

but problem is when i retrieve record its give me readable format instead of unix timestamp so how i get value as store in database i.e(1593624368). in database i use int(11) data-type for created_at and updated_at

created_at: 2020-07-01T17:45:03.000000Z,
updated_at: 2020-07-02T08:53:14.000000Z,
2

1 Answer 1

1

U can use Laravel Date Casting

For your case:

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'created_at' => 'timestamp',
    'updated_at' => 'timestamp',
];
Sign up to request clarification or add additional context in comments.

2 Comments

let me try this
check update, test in Tinker and get proper format, in my case 1581346827

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.