$serverVariable * @property-read int|null $server_variable_count * * @method static \Database\Factories\EggVariableFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|EggVariable newQuery() * @method static \Illuminate\Database\Eloquent\Builder|EggVariable query() * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereDefaultValue($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereEggId($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereEnvVariable($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereRules($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereSort($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereUserEditable($value) * @method static \Illuminate\Database\Eloquent\Builder|EggVariable whereUserViewable($value) * * @property string|null $server_value This variable is only present on the object if you've loaded this model using the server relationship. */ class EggVariable extends Model implements Validatable { use HasFactory; use HasValidation { getRules as getValidationRules; } /** * The resource name for this model when it is transformed into an * API representation using fractal. */ public const RESOURCE_NAME = 'egg_variable'; /** * Reserved environment variable names. */ public const RESERVED_ENV_NAMES = ['P_SERVER_UUID', 'P_SERVER_ALLOCATION_LIMIT', 'SERVER_MEMORY', 'SERVER_IP', 'SERVER_PORT', 'ENV', 'HOME', 'USER', 'STARTUP', 'MODIFIED_STARTUP', 'SERVER_UUID', 'UUID', 'INTERNAL_IP', 'HOSTNAME', 'TERM', 'LANG', 'PWD', 'TZ', 'TIMEZONE']; /** * Fields that are not mass assignable. */ protected $guarded = ['id', 'created_at', 'updated_at']; /** @var array */ public static array $validationRules = [ 'egg_id' => ['exists:eggs,id'], 'sort' => ['nullable'], 'name' => ['required', 'string', 'between:1,255'], 'description' => ['string'], 'default_value' => ['string'], 'user_viewable' => ['boolean'], 'user_editable' => ['boolean'], 'rules' => ['array'], 'rules.*' => ['string'], ]; /** * Implement language verification by overriding Eloquence's gather rules function. * * @return array */ public static function getRules(): array { $rules = self::getValidationRules(); $rules['env_variable'] = ['required', 'alphaDash', 'between:1,255', 'notIn:' . implode(',', EggVariable::RESERVED_ENV_NAMES)]; return $rules; } protected $attributes = [ 'user_editable' => 0, 'user_viewable' => 0, 'rules' => '[]', ]; protected function casts(): array { return [ 'egg_id' => 'integer', 'user_viewable' => 'bool', 'user_editable' => 'bool', 'rules' => 'array', 'created_at' => 'immutable_datetime', 'updated_at' => 'immutable_datetime', ]; } public function getRequiredAttribute(): bool { return in_array('required', $this->rules); } public function egg(): HasOne { return $this->hasOne(Egg::class); } /** * Return server variables associated with this variable. */ public function serverVariable(): HasMany { return $this->hasMany(ServerVariable::class, 'variable_id'); } }