🎨 Tente d'ajouter le rappel journalier

This commit is contained in:
Shikiryu 2019-09-25 16:08:50 +02:00
parent 70afcacd21
commit 333f6feafb
4 changed files with 91 additions and 0 deletions

View File

@ -2,8 +2,12 @@
namespace App\Console; namespace App\Console;
use App\Jobs\SendReminderEmail;
use App\Jobs\SendWelcomeEmail;
use App\User;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Carbon;
class Kernel extends ConsoleKernel class Kernel extends ConsoleKernel
{ {
@ -24,6 +28,15 @@ class Kernel extends ConsoleKernel
*/ */
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {
$schedule->call(function() {
$users = User::where('email_verified_at', '!=', null)
->where('notification_hour', '!=', null)
->get();
var_dump(count($users));
foreach ($users as $user) {
dispatch((new SendReminderEmail($user)));
}
})->everyMinute();
// $schedule->command('inspire') // $schedule->command('inspire')
// ->hourly(); // ->hourly();
} }

View File

@ -0,0 +1,40 @@
<?php
namespace App\Jobs;
use App\Mail\ReminderMail;
use App\Mail\WelcomeMail;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
class SendReminderEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $user;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::to($this->user->getEmailForVerification())
->queue(new ReminderMail($this->user));
}
}

37
app/Mail/ReminderMail.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ReminderMail extends Mailable
{
use Queueable, SerializesModels;
/** @var \App\User */
private $user;
/**
* Create a new message instance.
*
* @param \App\User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.reminder', ['user' => $this->user]);
}
}

View File

@ -0,0 +1 @@
<?php