*/ use HasFactory; /** * The resource name for this model when it is transformed into an * API representation using fractal. */ public const string RESOURCE_NAME = 'server_database'; /** * @return array */ protected function casts(): array { return [ 'server_id' => 'integer', 'database_host_id' => 'integer', 'max_connections' => 'integer', ]; } public function getRouteKeyName(): string { return $this->getKeyName(); } /** * Resolves the database using the ID by checking if the value provided is a HashID * string value, or just the ID to the database itself. * * @param string|null $field */ public function resolveRouteBinding($value, $field = null): ?\Illuminate\Database\Eloquent\Model { if (($field ?? $this->getRouteKeyName()) === 'id' && (is_string($value) || is_int($value))) { $value = is_int($value) || ctype_digit($value) ? $value : Hashids::decodeFirst($value); } return $this->where($field ?? $this->getRouteKeyName(), $value)->firstOrFail(); } /** * Gets the host database server associated with a database. * * @return BelongsTo */ public function host(): BelongsTo { return $this->belongsTo(DatabaseHost::class, 'database_host_id'); } /** * Gets the server associated with a database. * * @return BelongsTo */ public function server(): BelongsTo { return $this->belongsTo(Server::class); } }