-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathResendLeadNotifications.php
More file actions
43 lines (31 loc) · 1.27 KB
/
ResendLeadNotifications.php
File metadata and controls
43 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace App\Console\Commands;
use App\Models\Lead;
use App\Notifications\NewLeadSubmitted;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
class ResendLeadNotifications extends Command
{
protected $signature = 'app:resend-lead-notifications {date : The date to resend leads from (Y-m-d)}';
protected $description = 'Re-send lead notifications to the sales email for leads submitted on or after a given date.';
public function handle(): void
{
$date = Carbon::createFromFormat('Y-m-d', $this->argument('date'))->startOfDay();
$leads = Lead::query()
->where('created_at', '>=', $date)
->orderBy('created_at')
->get();
if ($leads->isEmpty()) {
$this->info('No leads found from '.$date->toDateString().' onwards.');
return;
}
$this->info("Found {$leads->count()} lead(s) from {$date->toDateString()} onwards.");
foreach ($leads as $lead) {
Notification::route('mail', 'sales@nativephp.com')
->notify(new NewLeadSubmitted($lead));
$this->line("Sent notification for lead: {$lead->company} ({$lead->email})");
}
$this->info('Done.');
}
}