Set default 'host' value for `php artisan serve`

元气小坏坏 提交于 2019-12-01 22:38:09

You can do next thing:

  1. php artisan make:command CustomServeCommand
  2. Then delete all from file and use this code:

    <?php
    
    namespace App\Console\Commands;
    
    use Illuminate\Foundation\Console\ServeCommand;
    use Symfony\Component\Console\Input\InputOption;
    
    class CustomServeCommand extends ServeCommand
    {
        /**
         * Get the console command options.
         *
         * @return array
         */
        protected function getOptions()
        {
            return [
                ['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', '0.0.0.0'],//default 127.0.0.1
                ['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 8000],
            ];
        }
    }
    
  3. php artisan serve

Link to the core file.

Basically, you will extend default class and adapt method to fit your own needs. This way you can set host and port per requirements.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!