AppModel.php 975 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * 描述.
  4. *
  5. * @author nj
  6. * @date 2021-05-18 20:46:19
  7. */
  8. namespace App\Models\Mysql;
  9. class AppModel extends BaseMysql
  10. {
  11. protected $table = 'app';
  12. /**
  13. * UUID 键名
  14. * @var string
  15. */
  16. protected $uuidKeyName = 'uid';
  17. /**
  18. * The "booted" method of the model.
  19. *
  20. * @return void
  21. */
  22. protected static function boot()
  23. {
  24. parent::boot();
  25. self::creating(function ($model) {
  26. $model->{$model->uuidKeyName} = self::generateId($model->uuidKeyName);
  27. });
  28. self::created(function ($model) {
  29. $uuid = hashEncodeId($model->id);
  30. $model->{$model->uuidKeyName} = $uuid;
  31. $model->save();
  32. });
  33. }
  34. /**
  35. * 关联多个渠道.
  36. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  37. */
  38. public function channels()
  39. {
  40. return $this->hasMany(ChannelModel::class, 'mom_app_uid', $this->uuidKeyName);
  41. }
  42. }