AiModel.php 739 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class AiModel extends Model
  6. {
  7. use HasFactory;
  8. protected $primaryKey = 'uid';
  9. /**
  10. * 主键 `uid` 是 uuid 字符串。
  11. *
  12. * 不声明这一行,Eloquent 按默认的 int 主键处理,关系预加载会走
  13. * `whereIntegerInRaw`,把 uuid 全部强转成 0(`where "uid" in (0)`)。
  14. * 下面的 casts 本来就写着 string,这里只是把两处声明对齐。
  15. *
  16. * 只影响关系预加载的取值方式;`$incrementing` 未动,写入行为不变。
  17. */
  18. protected $keyType = 'string';
  19. protected $casts = [
  20. 'uid' => 'string',
  21. ];
  22. }