✨ Ajoute la notification journalière
Il manque l'intégration du mail Pour #13
This commit is contained in:
66
app/Console/Commands/SendDailyNotification.php
Normal file
66
app/Console/Commands/SendDailyNotification.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Exceptions\WrongHourException;
|
||||
use App\Mail\DailyNotification;
|
||||
use App\Services\HourService;
|
||||
use App\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendDailyNotification extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'send:daily';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Send daily notification to write a post';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @param HourService $hour_service
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(HourService $hour_service)
|
||||
{
|
||||
try {
|
||||
$notification_id = $hour_service->getCurrentNotificationId();
|
||||
$this->info(sprintf('Notification id = %s', $notification_id));
|
||||
} catch (WrongHourException $e) {
|
||||
$this->error($e->getMessage());
|
||||
exit;
|
||||
}
|
||||
$users = User::where('notification_hour', '=', $notification_id)
|
||||
->where('email_verified_at', '!=', null)
|
||||
->whereNotExists(function($query) {
|
||||
$query->select()
|
||||
->from('posts')
|
||||
->whereRaw('posts.user_id = users.id')
|
||||
->whereDate('date_post', date('Y-m-d'));
|
||||
})
|
||||
->get();
|
||||
foreach ($users as $user) {
|
||||
Mail::to($user)->queue(new DailyNotification($user));
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\SendDailyNotification;
|
||||
use App\Jobs\SendReminderEmail;
|
||||
use App\Jobs\SendWelcomeEmail;
|
||||
use App\User;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@@ -17,7 +16,7 @@ class Kernel extends ConsoleKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
SendDailyNotification::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -28,17 +27,17 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule
|
||||
->command('send:daily')
|
||||
->cron('0 */6 * * *');
|
||||
|
||||
$schedule->call(function() {
|
||||
$users = User::where('email_verified_at', '!=', null)
|
||||
->where('notification_hour', '!=', null)
|
||||
$users = User::where('email_verified_at', '=', null)
|
||||
->get();
|
||||
var_dump(count($users));
|
||||
foreach ($users as $user) {
|
||||
dispatch((new SendReminderEmail($user)));
|
||||
}
|
||||
})->everyMinute();
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
})->daily();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user