我已经创建了一个命令并计划了它。更新数据库时,该命令运行正常。无论如何,发送电子邮件都会出现[undefined index:HTTP_POST]错误。我一直在搜索google一段时间,似乎没有任何帮助解决该问题的方法。任何帮助将不胜感激。
我正在使用laravel 5.4
下面是我的可邮寄课程
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Http\Request;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendMailable extends Mailable
{
use Queueable, SerializesModels;
public $number;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($number)
{
$this->$number = $number;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.weekly');
}
}
下面是我的命令
<?php
namespace App\Console\Commands;
use Illuminate\Http\Request;
use App\Jobs;
use App\User;
use Illuminate\Support\Facades\Mail;
use Illuminate\Console\Command;
use App\Mail\SendMailable;
class WeeklyEmails extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update:users';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send updates on latest Internships';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
/*
* This part works as expected
*
*/
$jobs = User::find(1);
$jobs->name = rand(10,100);
if($jobs->save()){
echo "User have been updated"."\n";
}
/*
* This part does not work at all it returns the: [undefined index: HTTP_POST] error
*
*/
Mail::to('example@gmail.com')->send(new SendMailable(5));
}
}
这是我的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\WeeklyEmails::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('update:users')
->daily();
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}