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_at 和 updated_at

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