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

眉间皱痕 提交于 2019-12-02 02:17:54

问题


I am building a Laravel site, and want to test it on other devices as I build it (phone, ipad etc).

As I understand it, the way to do this is to run php artisan serve --host=0.0.0.0.

My question is... is there a way to define a default value for the host, and set it to 0.0.0.0, so that I can simply run php artisan serve and it will automatically run on 0.0.0.0?


回答1:


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.



来源:https://stackoverflow.com/questions/50639622/set-default-host-value-for-php-artisan-serve

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