dongshan4316 2019-01-14 21:32
浏览 24
已采纳

如何让当前用户执行Laravel命令?

I am trying to build a custom configuration that gets added to my Laravel configuration at boot up. I created an artisan command that allows the developers to place the server into 'test' mode and 'live' mode. This should then force API's to use test keys rather than live keys which works fine.

public function handle()
{
    switch(strtoupper($this->argument('m'))) {
        case 'LIVE':
            \DB::table('server_mode')->where('id', 1)->update([
                'mode' => true,
                'verified_by' => 'Server'
            ]);
            $this->info('Server is now in LIVE mode');
            break;
        case 'TEST':
            \DB::table('server_mode')->where('id', 1)->update([
                'mode' => false,
                'verified_by' => 'Server'
            ]);
            $this->info('Server is now in TEST mode');
            break;
        default:
            $this->error('Please enter either LIVE or TEST');
            break;
    }
}

The problem is, I want to add which developer changed the status. So far, it is hard coded to 'Server'. Is it possible to get the IP or PC information who'm executed the command to store in the DB?

  • 写回答

1条回答 默认 最新

  • duanchai0028 2019-01-14 21:47
    关注

    As said in the comments, Jaquarh doesn't try to authenticate. He just wants to get the username of the perso who ran the command.

    You can use $processUser = exec('whoami'); to get the current user name. (It won't work on windows)

    However, be careful, usernames are not always very informative. My laptop at work came preinstalled with a user name "User".

    Another idea that I can suggest is to force a "name" parameter when using your command.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作