AuthBaseModel.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: vien
  5. * Date: 2019/3/17
  6. * Time: 3:04 PM
  7. */
  8. namespace App\Models\Base;
  9. use Illuminate\Database\Eloquent\SoftDeletes;
  10. use Illuminate\Foundation\Auth\User as Authenticatable;
  11. class AuthBaseModel extends Authenticatable
  12. {
  13. use SoftDeletes;
  14. protected $allowEmpty = [];
  15. /**
  16. * 需要转换成日期的属性
  17. *
  18. * @var array
  19. */
  20. protected $dates = ['deleted_at'];
  21. /**
  22. * 默认使用时间戳戳功能
  23. *
  24. * @var bool
  25. */
  26. public $timestamps = true;
  27. /**
  28. * 获取当前时间
  29. *
  30. * @return int
  31. */
  32. public function freshTimestamp() {
  33. return time();
  34. }
  35. /**
  36. * 避免转换时间戳为时间字符串
  37. *
  38. * @param DateTime|int $value
  39. * @return DateTime|int
  40. */
  41. public function fromDateTime($value) {
  42. return $value;
  43. }
  44. /**
  45. * select的时候避免转换时间为Carbon
  46. *
  47. * @param mixed $value
  48. * @return mixed
  49. */
  50. // protected function asDateTime($value) {
  51. // return $value;
  52. // }
  53. /**
  54. * 从数据库获取的为获取时间戳格式
  55. *
  56. * @return string
  57. */
  58. public function getDateFormat() {
  59. return 'U';
  60. }
  61. }