class BaseModel extends Eloquent {

  /**
   * 默认使用时间戳戳功能
   *
   * @var bool
   */
  public $timestamps = true;

  /**
   * 获取当前时间
   *
   * @return int
   */
  public function freshTimestamp() {
    return time();
  }

  /**
   * 避免转换时间戳为时间字符串
   *
   * @param DateTime|int $value
   * @return DateTime|int
   */
  public function fromDateTime($value) {
    return $value;
  }

  /**
   * select的时候避免转换时间为Carbon
   *
   * @param mixed $value
   * @return mixed
   */
//  protected function asDateTime($value) {
//      return $value;
//  }

  /**
   * 从数据库获取的为获取时间戳格式
   *
   * @return string
   */
  public function getDateFormat() {
    return 'U';
  }

}

 

相关文章:

  • 2021-08-06
  • 2022-02-03
  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
  • 2021-11-04
猜你喜欢
  • 2022-12-23
  • 2022-02-24
  • 2021-07-25
  • 2021-11-11
  • 2021-09-20
相关资源
相似解决方案