BaseModel.php 756 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Models;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\Model;
  5. class BaseModel extends Model
  6. {
  7. /**
  8. * 自动维护时间戳created_at和updated_at
  9. *
  10. * @var bool
  11. */
  12. public $timestamps = true;
  13. /**
  14. * 自增主键
  15. * @var bool
  16. */
  17. public $incrementing = true;
  18. /**
  19. * 保护字段.
  20. * @var string[]
  21. */
  22. protected $guarded = ['id'];
  23. /**
  24. * 定义分页尺码
  25. *
  26. * @var int
  27. */
  28. protected $perPage = 20;
  29. /**
  30. * 时间序列化修改
  31. *
  32. * @param DateTimeInterface $date
  33. * @return string
  34. */
  35. protected function serializeDate(DateTimeInterface $date)
  36. {
  37. return $date->format("Y-m-d H:i:s");
  38. }
  39. }