Я хотел бы реализовать «электронное письмо-напоминание», которое будет отправлено в определенную дату;
Миграция:
Schema::create('todos', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('importance');
$table->date('when');
$table->timestamps();
$table->string('to');
});
(адрес электронной почты будет адресом пользователя, который создалэто напоминание).
Команда:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Todo;
use Illuminate\Support\Facades\Mail;
use App\Mail\EmailReminder;
class SendEmails extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'email:reminder';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send reminder e-mails to a users';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() //Todo $todo
{
parent::__construct();
//$this->todo = $todo;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(Request $request, $id, $todo)
{
$i = 0;
$todo = Todo::whereMonth('when', '=', date('m'))->whereDay('when', '=', date('d'))->get();
foreach($todo as $todo)
{
$email = $todo->email;
Mail::to($email)->send(new BirthdayReminder($todo));
$i++;
}
}
}
Почта:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Todo;
class EmailReminder extends Mailable
{
use Queueable, SerializesModels;
public $todo;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Todo $todo)
{
$this->todo = $todo;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$todo = $this->todo;
return $this->from('friendlyreminder@yourcompany.rs')
->view('emails.reminder',compact('todo'));
//Mail::to(Auth::user()->email)->send(new EmailReminder());
}
}
Ядро:
protected function schedule(Schedule $schedule)
{
$schedule->command('email:reminder')->everyMinute();
}
Проблема в том, когда я пытаюсьphp artisan email: напоминание, я получаю сообщение об ошибке «Class App \ Console \ Commands \ Request not Существует».
Я действительно озадачен и проверил подобные вопросы здесь, в StackOverlow, и погуглил его, но могуне в состоянии понять это.Любая помощь приветствуется.