Created
November 24, 2025 13:09
-
-
Save palaueb/3941d72fc317f99f1184503c792764a9 to your computer and use it in GitHub Desktop.
automatic port patch for php artisan serv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // It reads the local.env file and uses the SERVER_PORT to handle the requests | |
| /** | |
| * Get the port for the command. | |
| * | |
| * @return string | |
| */ | |
| protected function port() | |
| { | |
| $port = $this->input->getOption('port'); | |
| if (is_null($port)) { | |
| [, $port] = $this->getHostAndPort(); | |
| } | |
| if (is_null($port)) { | |
| $basePath = base_path(); // ruta arrel del projecte | |
| if (file_exists($basePath . '/.env')) { | |
| $dotenv = Dotenv::createImmutable($basePath); | |
| $envContent = $dotenv->parse(file_get_contents($basePath . '/.env')); | |
| $port = $envContent['SERVER_PORT'] ?? null; | |
| } | |
| } | |
| $port = $port ?: 8000; | |
| return $port + $this->portOffset; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment