*/ public static array $validationRules = [ 'name' => ['required', 'string', 'max:255'], 'host' => ['required', 'string'], 'port' => ['required', 'numeric', 'between:1,65535'], 'username' => ['required', 'string', 'max:32'], 'password' => ['nullable', 'string'], 'node_ids' => ['nullable', 'array'], 'node_ids.*' => ['required', 'integer,exists:nodes,id'], ]; protected function casts(): array { return [ 'id' => 'integer', 'max_databases' => 'integer', 'password' => 'encrypted', 'created_at' => 'immutable_datetime', 'updated_at' => 'immutable_datetime', ]; } public function nodes(): BelongsToMany { return $this->belongsToMany(Node::class); } /** * Gets the databases associated with this host. */ public function databases(): HasMany { return $this->hasMany(Database::class); } public function buildConnection(string $database = 'mysql', string $charset = 'utf8', string $collation = 'utf8_unicode_ci'): Connection { /** @var Connection $connection */ $connection = DB::build([ 'driver' => 'mysql', 'host' => $this->host, 'port' => $this->port, 'database' => $database, 'username' => $this->username, 'password' => $this->password, 'charset' => $charset, 'collation' => $collation, ]); return $connection; } }