-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathSendUltraFreeUserPromotion.php
More file actions
48 lines (36 loc) · 1.33 KB
/
SendUltraFreeUserPromotion.php
File metadata and controls
48 lines (36 loc) · 1.33 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
44
45
46
47
48
<?php
namespace App\Console\Commands;
use App\Models\User;
use App\Notifications\UltraFreeUserPromotion;
use Illuminate\Console\Command;
class SendUltraFreeUserPromotion extends Command
{
protected $signature = 'ultra:send-free-user-promo
{--dry-run : Show what would be sent without actually sending}';
protected $description = 'Send a promotional email to users who signed up but never purchased a license or subscription, encouraging them to try Ultra';
public function handle(): int
{
$dryRun = $this->option('dry-run');
if ($dryRun) {
$this->info('DRY RUN - No emails will be sent');
}
$users = User::query()
->whereDoesntHave('licenses')
->whereDoesntHave('subscriptions')
->get();
$sent = 0;
foreach ($users as $user) {
if ($dryRun) {
$this->line("Would send to: {$user->email}");
} else {
$user->notify(new UltraFreeUserPromotion);
$this->line("Sent to: {$user->email}");
}
$sent++;
}
$this->newLine();
$this->info("Found {$sent} eligible user(s)");
$this->info($dryRun ? "Would send: {$sent} email(s)" : "Sent: {$sent} email(s)");
return Command::SUCCESS;
}
}