✨ 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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user