Laravel太多的论点,预期的论点"命令"安排时

时间:2017-02-01 08:19:18

标签: php laravel laravel-5 laravel-5.2 laravel-5.3

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

一切正常,计划功能被触发但出现错误

 [Symfony\Component\Console\Exception\RuntimeException]
  Too many arguments, expected arguments "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('info@XXXXXX.com', 'Company')
                ->subject('Happy Birthday!');
        });

     }

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

    }
}

这是我的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');
    }
}

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

2 个答案:

答案 0 :(得分:2)

我找到了解决方案,

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

最初我有一个时间表:run方法。如下

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

答案 1 :(得分:1)

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

php artisan schedule:run
到达根文件夹路径后