| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Models\Mysql;
- class AppDeductionRuleModel extends BaseMysql
- {
- protected $table = 'app_deduction_rule';
- private static $appData = [];
- protected $appends = ['app_name'];
- /**
- * The "booted" method of the model.
- *
- * @return void
- */
- protected static function boot()
- {
- parent::boot();
- self::created(function ($model) {
- $uuid = hashEncodeId($model->id);
- $model->uid = $uuid;
- $model->save();
- });
- }
- /**
- * 获取应用名称
- *
- * directions 使用静态方法,获取app应用名称只会查询一次
- * @return \Illuminate\Database\Eloquent\HigherOrderBuilderProxy|mixed
- */
- public function getAppNameAttribute()
- {
- if (empty(self::$appData)) {
- self::$appData = AppModel::query()->select('uid', 'name')->get()->keyBy('uid');
- }
- return $this->app_name = self::$appData[$this->app_uid]->name ?? '';
- }
- }
|