为"php artisan serve"设置默认的“主机"值 [英] Set default 'host' value for `php artisan serve`

查看:250
本文介绍了为"php artisan serve"设置默认的“主机"值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Laravel网站,并希望在构建它的其他设备(电话,ipad等)上对其进行测试.

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

据我了解,执行此操作的方法是运行php artisan serve --host=0.0.0.0.

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

我的问题是...有没有一种方法可以为主机定义默认值,并将其设置为0.0.0.0,这样我就可以简单地运行php artisan serve,它将自动在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. php artisan make:command CustomServeCommand
  2. 然后从文件中删除所有文件并使用此代码:

  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],
        ];
    }
}

  • php artisan serve

    链接到核心文件.

    基本上,您将扩展默认类和适应方法以满足您自己的需求.这样,您可以根据要求设置主机和端口.

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

    这篇关于为"php artisan serve"设置默认的“主机"值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆