dsv38843 2019-01-25 03:31
浏览 69
已采纳

在laravel控制器中运行自定义工匠命令

I have custom command like:

php artisan down --message="this is my custom message."

Now I want to use this command in my controller with input fields.

I know I can use Call method like Artisan::call('down'); but my issue is how to add --message="" part into that call method?

Data

this is what I'm sending to controller currently:

array:3 [▼
  "_token" => "wqHyTNmDhArtonB0gwhIbCipSsStv0WnoASQm34u"
  "maintenance_message" => "this is my custom message."
  "maintenance" => "active"
]

Now based on maintenance value i will call Artisan::call('up'); or Artisan::call('down'); but the question is how do i add maintenance_message into it?

Code

This is my current function.

public function MaintenanceMode(Request $request){
  if($request->input('maintenance') == 'active'){
    //maintenance_message
    Session::flash('danger', 'Site is successfully in maintenance mode.');
    return Artisan::call('down');
  }else{
    //maintenance_message
    Session::flash('success', 'Site is ONLINE.');
    return Artisan::call('up');
  }
}

Any idea?

  • 写回答

2条回答 默认 最新

  • du20150401 2019-01-25 03:37
    关注

    The documentation has some examples of this:

    https://laravel.com/docs/5.7/artisan#programmatically-executing-commands

    The call method accepts either the command's name or class as the first argument, and an array of command parameters as the second argument. The exit code will be returned:

    Route::get('/foo', function () {
        $exitCode = Artisan::call('email:send', [
            'user' => 1, '--queue' => 'default'
        ]);
    
        //
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换