• <i id='7Zwq9'><tr id='7Zwq9'><dt id='7Zwq9'><q id='7Zwq9'><span id='7Zwq9'><b id='7Zwq9'><form id='7Zwq9'><ins id='7Zwq9'></ins><ul id='7Zwq9'></ul><sub id='7Zwq9'></sub></form><legend id='7Zwq9'></legend><bdo id='7Zwq9'><pre id='7Zwq9'><center id='7Zwq9'></center></pre></bdo></b><th id='7Zwq9'></th></span></q></dt></tr></i><div id='7Zwq9'><tfoot id='7Zwq9'></tfoot><dl id='7Zwq9'><fieldset id='7Zwq9'></fieldset></dl></div>
  • <tfoot id='7Zwq9'></tfoot>
  • <legend id='7Zwq9'><style id='7Zwq9'><dir id='7Zwq9'><q id='7Zwq9'></q></dir></style></legend>
    • <bdo id='7Zwq9'></bdo><ul id='7Zwq9'></ul>
  • <small id='7Zwq9'></small><noframes id='7Zwq9'>

        Laravel 5 - 如何从 Artisan 命令运行控制器方法?

        Laravel 5 - how to run a Controller method from an Artisan Command?(Laravel 5 - 如何从 Artisan 命令运行控制器方法?)
        • <tfoot id='RMALD'></tfoot>

        • <legend id='RMALD'><style id='RMALD'><dir id='RMALD'><q id='RMALD'></q></dir></style></legend>
            <tbody id='RMALD'></tbody>

              <i id='RMALD'><tr id='RMALD'><dt id='RMALD'><q id='RMALD'><span id='RMALD'><b id='RMALD'><form id='RMALD'><ins id='RMALD'></ins><ul id='RMALD'></ul><sub id='RMALD'></sub></form><legend id='RMALD'></legend><bdo id='RMALD'><pre id='RMALD'><center id='RMALD'></center></pre></bdo></b><th id='RMALD'></th></span></q></dt></tr></i><div id='RMALD'><tfoot id='RMALD'></tfoot><dl id='RMALD'><fieldset id='RMALD'></fieldset></dl></div>

              <small id='RMALD'></small><noframes id='RMALD'>

                • <bdo id='RMALD'></bdo><ul id='RMALD'></ul>
                  本文介绍了Laravel 5 - 如何从 Artisan 命令运行控制器方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要我的控制器中的一些代码每十分钟运行一次.使用 SchedulerCommands 就足够简单了.但.我创建了一个 Command,用 Laravel Scheduler(在 Kernel.php 中)注册它,现在我无法实例化 控制器.我知道这是解决此问题的错误方法,但我只需要进行快速测试.有没有办法,请注意一个hacky的方式,来完成这个?谢谢.

                  更新 #1:

                  命令:

                  ');}}

                  StatsController.php

                  中的

                  updateStats() 方法

                  公共静态函数 updateStats($theProfileName) {//身体}

                  这将返回一个FatalErrorException:

                  [SymfonyComponentDebugExceptionFatalErrorException]语法错误,意外的if"(T_IF)

                  更新#2:

                  结果是我在 updateStats() 方法中有一个错字,但@alexey-mezenin 的回答很有魅力!把Controller导入Command也够了:

                  使用 AppHttpControllersStatsController;

                  然后像往常一样初始化它:

                  公共函数句柄() {$statControl = 新的 StatsController;$statControl->updateStats('');}

                  解决方案

                  尝试在命令代码中使用 use FullPathToYourController; 并静态使用方法:

                  公共静态函数 someStaticMethod(){返回你好";}

                  在您的命令代码中:

                  echo myClass::someStaticMethod();

                  I need some code from my Controller to run every ten minutes. Easy enough with Scheduler and Commands. But. I've created a Command, registered it with Laravel Scheduler (in Kernel.php) and now I am unable to instantiate the Controller. I know it's a wrong way to approach this problem, but I just needed a quick test. Is there a way, mind you a hacky way, to accomplish this? Thank you.

                  Update #1:

                  The Command:

                  <?php
                  
                  namespace AppConsoleCommands;
                  
                  use IlluminateConsoleCommand;
                  use AppHttpControllersStatsController;
                  
                  
                  class UpdateProfiles extends Command
                  {
                      /**
                       * The name and signature of the console command.
                       *
                       * @var string
                       */
                      protected $signature = 'update-profiles';
                  
                      /**
                       * The console command description.
                       *
                       * @var string
                       */
                      protected $description = 'Updates profiles in database.';
                  
                      /**
                       * Create a new command instance.
                       *
                       * @return void
                       */
                      public function __construct()
                      {
                          parent::__construct();
                      }
                  
                      /**
                       * Execute the console command.
                       *
                       * @return mixed
                       */
                      public function handle()
                      {
                          StatsController::updateStats('<theProfileName>');
                      }
                  }
                  

                  updateStats() method in StatsController.php

                  public static function updateStats($theProfileName) { 
                     // the body
                  }
                  

                  This returns a FatalErrorException:

                  [SymfonyComponentDebugExceptionFatalErrorException] 
                  syntax error, unexpected 'if' (T_IF)
                  

                  Update #2:

                  Turns out that I've had an typo in the updateStats() method, but the answer by @alexey-mezenin works like a charm! It is also enough to import the Controller into the Command:

                  use AppHttpControllersStatsController;
                  

                  And then initialize it as you'd do normally:

                  public function handle() {
                     $statControl        = new StatsController;
                     $statControl->updateStats('<theProfileName>');
                  }
                  

                  解决方案

                  Try to use use FullPathToYourController; in your command code and use method statically:

                  public static function someStaticMethod()
                  {
                      return 'Hello';
                  }
                  

                  In your command code:

                  echo myClass::someStaticMethod();
                  

                  这篇关于Laravel 5 - 如何从 Artisan 命令运行控制器方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  1. <small id='UlAMq'></small><noframes id='UlAMq'>

                      <legend id='UlAMq'><style id='UlAMq'><dir id='UlAMq'><q id='UlAMq'></q></dir></style></legend>
                    1. <tfoot id='UlAMq'></tfoot>

                          <i id='UlAMq'><tr id='UlAMq'><dt id='UlAMq'><q id='UlAMq'><span id='UlAMq'><b id='UlAMq'><form id='UlAMq'><ins id='UlAMq'></ins><ul id='UlAMq'></ul><sub id='UlAMq'></sub></form><legend id='UlAMq'></legend><bdo id='UlAMq'><pre id='UlAMq'><center id='UlAMq'></center></pre></bdo></b><th id='UlAMq'></th></span></q></dt></tr></i><div id='UlAMq'><tfoot id='UlAMq'></tfoot><dl id='UlAMq'><fieldset id='UlAMq'></fieldset></dl></div>
                            <tbody id='UlAMq'></tbody>
                            <bdo id='UlAMq'></bdo><ul id='UlAMq'></ul>