| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Module\Pet\Models;
- use App\Module\Pet\Casts\GradeProbability;
- use UCore\ModelCore;
- use App\Module\Pet\Casts\DisplayAttributesCast;
- use App\Module\Pet\Casts\NumericAttributesCast;
- /**
- * 宠物配置模型
- *
- * field start
- * @property int $id
- * @property string $pet_type 宠物类型
- * @property object|array $grade_probability 品阶概率配置
- * @property object|array $display_attributes 显示属性配置
- * @property object|array $numeric_attributes 数值属性配置
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
- * field end
- */
- class PetConfig extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'pet_configs';
- // attrlist start
- protected $fillable = [
- 'id',
- 'pet_type',
- 'grade_probability',
- 'display_attributes',
- 'numeric_attributes',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'grade_probability' => GradeProbability::class,
- 'display_attributes' => DisplayAttributesCast::class,
- 'numeric_attributes' => NumericAttributesCast::class,
- ];
- /**
- * 获取指定宠物类型的配置
- *
- * @param string $petType
- * @return self|null
- */
- public static function getByType(string $petType): ?self
- {
- return self::where('pet_type', $petType)->first();
- }
- }
|