Laravel timestamps 设置为unix时间戳

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Divide_/article/details/68059626

Laravel 修改 timestamps 为 unix 时间戳

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * Class Test
 * @package App
 */
class Test extends Model
{
    /**
     * @var string
     */
    protected $table='test';
    /**
     * @var array
     */
    protected $fillable = [
        'name', 'tel'
    ];

    /**
     * @param \DateTime|int $value
     * @return false|int
     * @author dividez
     */
    public function fromDateTime($value){
        return strtotime(parent::fromDateTime($value));
    }
}

这样修改以后 laravel 依然会自动维护 created_atupdated_at

在我们取出 created_at 这个字段依然会为我们转换为 Carbon 类型

猜你喜欢

转载自blog.csdn.net/Divide_/article/details/68059626
今日推荐