Skip to content

Commit be874dd

Browse files
authored
Merge pull request #57 from laravelcm/welcome-mail
Welcome mail
2 parents d764630 + eff62cc commit be874dd

39 files changed

+1124
-376
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DB_PASSWORD=
1616

1717
BROADCAST_DRIVER=log
1818
CACHE_DRIVER=file
19-
QUEUE_CONNECTION=sync
19+
QUEUE_CONNECTION=database
2020
SESSION_DRIVER=database
2121
SESSION_LIFETIME=120
2222

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\User;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Mail;
8+
9+
class SendWelcomeMailToUsers extends Command
10+
{
11+
protected $signature = 'lcm:send-welcome-mails';
12+
13+
protected $description = 'Send mails to new registered users.';
14+
15+
public function handle(): void
16+
{
17+
foreach (User::all() as $user) {
18+
Mail::to($user)->queue(new \App\Mail\Welcome($user));
19+
}
20+
}
21+
}

app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function schedule(Schedule $schedule)
2626
{
2727
// $schedule->command('media-library:delete-old-temporary-uploads')->daily();
2828
$schedule->command('lcm:delete-old-unverified-users')->daily();
29-
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
29+
$schedule->command('lcm:post-article-to-twitter')->everyFourHours();
3030
$schedule->command('lcm:post-article-to-telegram')->everyFourHours();
3131
$schedule->command('lcm:send-unverified-mails')->weeklyOn(1, '8:00');
3232
$schedule->command('sitemap:generate')->daily();

app/Listeners/SendNewReplyNotification.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
use App\Events\ReplyWasCreated;
66
use App\Models\User;
77
use App\Notifications\NewReplyNotification;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Queue\InteractsWithQueue;
810

9-
class SendNewReplyNotification
11+
class SendNewReplyNotification implements ShouldQueue
1012
{
13+
use InteractsWithQueue;
14+
1115
public function handle(ReplyWasCreated $event)
1216
{
1317
/** @var \App\Models\Thread $thread */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Models\User;
6+
use Illuminate\Auth\Events\Registered;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Queue\InteractsWithQueue;
9+
use Illuminate\Support\Facades\Mail;
10+
11+
class SendWelcomeMailNotification implements ShouldQueue
12+
{
13+
use InteractsWithQueue;
14+
15+
/**
16+
* Handle the event.
17+
*
18+
* @param Registered $event
19+
* @return void
20+
*/
21+
public function handle(Registered $event)
22+
{
23+
/** @var User $user */
24+
$user = $event->user;
25+
26+
Mail::to($user)->queue(new \App\Mail\Welcome($user));
27+
}
28+
}

app/Mail/NewReplyEmail.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
use App\Models\Reply;
66
use App\Models\Subscribe;
7+
use Illuminate\Bus\Queueable;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
79
use Illuminate\Mail\Mailable;
810

9-
class NewReplyEmail extends Mailable
11+
class NewReplyEmail extends Mailable implements ShouldQueue
1012
{
13+
use Queueable;
14+
1115
/**
1216
* Create a new message instance.
1317
*

app/Mail/SendMailToUnVerifiedUsers.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use App\Models\User;
66
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
78
use Illuminate\Mail\Mailable;
89
use Illuminate\Queue\SerializesModels;
910

10-
class SendMailToUnVerifiedUsers extends Mailable
11+
class SendMailToUnVerifiedUsers extends Mailable implements ShouldQueue
1112
{
1213
use Queueable, SerializesModels;
1314

app/Mail/Welcome.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Mail;
4+
5+
use App\Models\User;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Mail\Mailable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class Welcome extends Mailable implements ShouldQueue
12+
{
13+
use Queueable, SerializesModels;
14+
15+
public function __construct(public User $user)
16+
{
17+
}
18+
19+
/**
20+
* Build the message.
21+
*
22+
* @return $this
23+
*/
24+
public function build()
25+
{
26+
return $this->from('arthur@laravel.cm', 'Arthur Monney')
27+
->subject(__('Bienvenue sur Laravel Cameroun ✨'))
28+
->markdown('emails.welcome');
29+
}
30+
}

app/Notifications/NewCommentNotification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
use App\Models\Reply;
77
use App\Models\Subscribe;
88
use Illuminate\Bus\Queueable;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
910
use Illuminate\Notifications\Messages\MailMessage;
1011
use Illuminate\Notifications\Notification;
1112

12-
class NewCommentNotification extends Notification
13+
class NewCommentNotification extends Notification implements ShouldQueue
1314
{
1415
use Queueable;
1516

app/Notifications/NewReplyNotification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
use App\Models\Reply;
77
use App\Models\Subscribe;
88
use Illuminate\Bus\Queueable;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
910
use Illuminate\Notifications\Notification;
1011

11-
class NewReplyNotification extends Notification
12+
class NewReplyNotification extends Notification implements ShouldQueue
1213
{
1314
use Queueable;
1415

app/Notifications/SendApprovedArticle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use App\Models\Article;
66
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
78
use Illuminate\Notifications\Messages\MailMessage;
89
use Illuminate\Notifications\Notification;
910

10-
class SendApprovedArticle extends Notification
11+
class SendApprovedArticle extends Notification implements ShouldQueue
1112
{
1213
use Queueable;
1314

app/Notifications/YouWereMentioned.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
namespace App\Notifications;
44

55
use App\Models\Reply;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
68
use Illuminate\Notifications\Messages\MailMessage;
79
use Illuminate\Notifications\Notification;
810

9-
class YouWereMentioned extends Notification
11+
class YouWereMentioned extends Notification implements ShouldQueue
1012
{
13+
use Queueable;
14+
1115
public function __construct(public Reply $reply)
1216
{
1317
}

app/Providers/EventServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Listeners\SendNewCommentNotification;
1313
use App\Listeners\SendNewReplyNotification;
1414
use App\Listeners\SendNewThreadNotification;
15+
use App\Listeners\SendWelcomeMailNotification;
1516
use Illuminate\Auth\Events\Registered;
1617
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
1718
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -26,6 +27,7 @@ class EventServiceProvider extends ServiceProvider
2627
protected $listen = [
2728
Registered::class => [
2829
SendEmailVerificationNotification::class,
30+
SendWelcomeMailNotification::class,
2931
],
3032
ReplyWasCreated::class => [
3133
SendNewReplyNotification::class,

0 commit comments

Comments
 (0)