php Laravel 参数太多,调度时预期参数“命令”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41974922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:31:14  来源:igfitidea点击:

Laravel Too many arguments, expected arguments "command" while scheduling

phplaravellaravel-5laravel-5.2laravel-5.3

提问by bobin56

This should be straigh forward buti don't know why it is not working . I am creating a command in laravel to send birtday email reminders on a user's birtday .

这应该是直接的,但我不知道为什么它不起作用。我正在 laravel 中创建一个命令来在用户的生日发送生日电子邮件提醒。

Everything works fine and the schedule function is triggered but comes with an error

一切正常,调度功能被触发,但出现错误

 [Symfony\Component\Console\Exception\RuntimeException]
  Too many arguments, expected arguments "command".

This is my command

这是我的命令

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\User;
class SendBirthdayReminderEmail extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'email:birthday';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Email users a birthday Reminder message';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

     $users = User::whereMonth('dob', '=', date('m'))->whereDay('dob', '=', date('d'))->get();   
    foreach($users as $user) {   
        Mail::queue('emails.birthday', ['user' => $user], function ($mail) use ($user) {
            $mail->to($user['email'])
                ->from('[email protected]', 'Company')
                ->subject('Happy Birthday!');
        });

     }

    $this->info('Birthday messages sent successfully!');

    }
}

And this is my kernel.php file

这是我的 kernel.php 文件

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
     Commands\SendBirthdayReminderEmail::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {


        $schedule->command('email:birthday')->dailyAt('13:00')->timezone('Africa/Dar_es_Salaam');
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

Any help will be appreciated . Thanks :-)

任何帮助将不胜感激 。谢谢 :-)

回答by bobin56

I found a solution,

我找到了解决办法,

/opt/php70/bin/php /home/sitename/public_html/artisan schedule:run >/dev/null 2>&1

initially i had 1 after schedule:run method . As below

最初我在 schedule:run 方法之后有 1 个。如下

/opt/php70/bin/php /home/sitename/public_html/artisan schedule:run 1 >/dev/null 2>&1

回答by Mahesh Yadav

Your code all looks good. Have you tried simply as below

你的代码看起来都不错。您是否尝试过如下简单

php artisan schedule:run

after reaching at your root folder path.

到达根文件夹路径后。