diff --git a/src/Illuminate/Foundation/Console/ServeCommand.php b/src/Illuminate/Foundation/Console/ServeCommand.php index e5477c28700b..331b9dbcb7a6 100644 --- a/src/Illuminate/Foundation/Console/ServeCommand.php +++ b/src/Illuminate/Foundation/Console/ServeCommand.php @@ -138,7 +138,9 @@ protected function serverCommand() */ protected function host() { - return $this->input->getOption('host'); + [$host, ] = $this->getHostAndPort(); + + return $host; } /** @@ -148,11 +150,32 @@ protected function host() */ protected function port() { - $port = $this->input->getOption('port') ?: 8000; + $port = $this->input->getOption('port'); + + if (is_null($port)) { + [, $port] = $this->getHostAndPort(); + } + + $port = $port ?: 8000; return $port + $this->portOffset; } + /** + * Get the host and port from the host option string. + * + * @return array + */ + protected function getHostAndPort() + { + $hostParts = explode(':', $this->input->getOption('host')); + + return [ + $hostParts[0], + $hostParts[1] ?? null, + ]; + } + /** * Check if the command has reached its max amount of port tries. *