| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- /**
- * 描述.
- *
- * @author nj
- * @date 2021-05-18 20:46:19
- */
- namespace App\Models\Mysql;
- class AppModel extends BaseMysql
- {
- protected $table = 'app';
- /**
- * UUID 键名
- * @var string
- */
- protected $uuidKeyName = 'uid';
- /**
- * The "booted" method of the model.
- *
- * @return void
- */
- protected static function boot()
- {
- parent::boot();
- self::creating(function ($model) {
- $model->{$model->uuidKeyName} = self::generateId($model->uuidKeyName);
- });
- self::created(function ($model) {
- $uuid = hashEncodeId($model->id);
- $model->{$model->uuidKeyName} = $uuid;
- $model->save();
- });
- }
- /**
- * 关联多个渠道.
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- */
- public function channels()
- {
- return $this->hasMany(ChannelModel::class, 'mom_app_uid', $this->uuidKeyName);
- }
- }
|