Send reminder email at certain date using Laravel

I would like to implement “reminder email” that will be sent on a certain date;

Migration:

Schema::create('todos', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('importance');            
    $table->date('when');
    $table->timestamps();
    $table->string('to');
});

(email address will be the address of the user who created this reminder).

Command:

<?php

namespace AppConsoleCommands;

use IlluminateConsoleCommand;
use AppTodo;
use IlluminateSupportFacadesMail;
use AppMailEmailReminder;

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++; 
           }

    }
}

Mailable:
<?php

namespace AppMail;

use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;
use AppTodo;


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('<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccaabea5a9a2a8a0b5bea9a1a5a2a8a9be8cb5a3b9beafa3a1bcada2b5e2bebf">[email protected]</a>')
              ->view('emails.reminder',compact('todo'));
        //Mail::to(Auth::user()->email)->send(new EmailReminder());
    }

}

Kernel:
protected function schedule(Schedule $schedule)
{
   $schedule->command('email:reminder')->everyMinute();

}

The issue is, when I try php artisan email:reminder, I receive error message “Class AppConsoleCommandsRequest does not exist”.

I’m really puzzled and did check similar questions here on StackOverlow and googled it, but can’t manage to figure it out. Any help is appreciated.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try adding use Request; to the imports at the beginning of your console command’s file.
Because Request is a facade and it belongs to the root namespace or, put a before its every usage.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x