Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ DB_USERNAME=root
DB_PASSWORD=password

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_USERNAME=Inbox-Name
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_NAME="${APP_NAME}"

GITHUB_ID=
Expand Down
7 changes: 2 additions & 5 deletions app/Events/EmailAddressWasChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
namespace App\Events;

use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class EmailAddressWasChanged
{
use Dispatchable;
use SerializesModels;

public function __construct(
public User $user
) {
public function __construct(public User $user)
{
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ public function __construct()
/**
* Handle a registration request for the application.
*
* @param RegisterRequest $request
* @param \App\Http\Requests\RegisterRequest $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function register(RegisterRequest $request)
{
event(new Registered($user = $this->create($request)));

session()->forget('githubData');

$this->guard()->login($user);

return $request->wantsJson()
Expand Down
13 changes: 9 additions & 4 deletions app/Http/Controllers/Forum/ThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Models\Tag;
use App\Models\Thread;
use App\Models\User;
use App\Notifications\ThreadDeletedNotification;
use App\Policies\ThreadPolicy;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
Expand Down Expand Up @@ -111,19 +112,23 @@ public function update(ThreadRequest $request, Thread $thread)

$this->dispatchSync(UpdateThread::fromRequest($thread, $request));

$thread = $thread->fresh();

$this->success('forum.threads.updated');

return redirect()->route('thread', $thread->slug());
return redirect()->route('thread', $thread->fresh()->slug());
}

public function delete(Thread $thread)
public function delete(Request $request, Thread $thread)
{
$this->authorize(ThreadPolicy::DELETE, $thread);

$this->dispatchSync(new DeleteThread($thread));

$request->whenFilled('reason', function () use ($thread) {
$thread->author()?->notify(
new ThreadDeletedNotification($thread, request('reason')),
);
});

$this->success('forum.threads.deleted');

return redirect()->route('forum');
Expand Down
18 changes: 18 additions & 0 deletions app/Listeners/RenewEmailVerificationNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\EmailAddressWasChanged;
use Illuminate\Contracts\Auth\MustVerifyEmail;

final class RenewEmailVerificationNotification
{
public function handle(EmailAddressWasChanged $event): void
{
if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
$event->user->sendEmailVerificationNotification();
}
}
}
15 changes: 0 additions & 15 deletions app/Listeners/SendEmailVerificationNotification.php

This file was deleted.

7 changes: 2 additions & 5 deletions app/Mail/ArticleApprovedEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

final class ArticleApprovedEmail extends Mailable
{
public $subscription;

public function __construct(
public Article $article
) {
public function __construct(public Article $article)
{
}

public function build()
Expand Down
19 changes: 19 additions & 0 deletions app/Mail/ThreadDeletedEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Mail;

use App\Models\Thread;
use Illuminate\Mail\Mailable;

final class ThreadDeletedEmail extends Mailable
{
public function __construct(public Thread $thread, public string $reason)
{
}

public function build()
{
return $this->subject('Your thread on Laravel.io was removed')
->markdown('emails.thread_deleted');
}
}
5 changes: 2 additions & 3 deletions app/Notifications/ArticleApprovedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ final class ArticleApprovedNotification extends Notification implements ShouldQu
{
use Queueable;

public function __construct(
public Article $article
) {
public function __construct(public Article $article)
{
}

public function via(User $user)
Expand Down
5 changes: 2 additions & 3 deletions app/Notifications/ArticleSubmitted.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class ArticleSubmitted extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(
private Article $article
) {
public function __construct(private Article $article)
{
}

public function via($notifiable)
Expand Down
5 changes: 2 additions & 3 deletions app/Notifications/MentionNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ final class MentionNotification extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(
public MentionAble $mentionAble,
) {
public function __construct(public MentionAble $mentionAble)
{
}

public function via(User $user)
Expand Down
6 changes: 2 additions & 4 deletions app/Notifications/NewReplyNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ final class NewReplyNotification extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(
public Reply $reply,
public Subscription $subscription
) {
public function __construct(public Reply $reply, public Subscription $subscription)
{
}

public function via(User $user)
Expand Down
5 changes: 2 additions & 3 deletions app/Notifications/PostArticleToTwitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class PostArticleToTwitter extends Notification
{
use Queueable;

public function __construct(
private Article $article
) {
public function __construct(private Article $article)
{
}

public function via($notifiable)
Expand Down
30 changes: 30 additions & 0 deletions app/Notifications/ThreadDeletedNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Notifications;

use App\Mail\ThreadDeletedEmail;
use App\Models\Thread;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class ThreadDeletedNotification extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(public Thread $thread, public ?string $reason = null)
{
}

public function via($notifiable)
{
return ['mail'];
}

public function toMail(User $user)
{
return (new ThreadDeletedEmail($this->thread, $this->reason))
->to($user->emailAddress(), $user->name());
}
}
40 changes: 20 additions & 20 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

use App\Events\ArticleWasApproved;
use App\Events\ArticleWasSubmittedForApproval;
use App\Events\EmailAddressWasChanged;
use App\Events\ReplyWasCreated;
use App\Events\ThreadWasCreated;
use App\Listeners\MarkLastActivity;
use App\Listeners\NotifyUsersMentionedInReply;
use App\Listeners\NotifyUsersMentionedInThread;
use App\Listeners\RenewEmailVerificationNotification;
use App\Listeners\SendArticleApprovedNotification;
use App\Listeners\SendNewArticleNotification;
use App\Listeners\SendNewReplyNotification;
use App\Listeners\StoreTweetIdentifier;
use App\Listeners\SubscribeUsersMentionedInReply;
use App\Listeners\SubscribeUsersMentionedInThread;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Notifications\Events\NotificationSent;

Expand All @@ -26,34 +30,30 @@ class EventServiceProvider extends ServiceProvider
* @var array
*/
protected $listen = [
ThreadWasCreated::class => [
SubscribeUsersMentionedInThread::class,
NotifyUsersMentionedInThread::class,
],
ReplyWasCreated::class => [
MarkLastActivity::class,
SendNewReplyNotification::class,
SubscribeUsersMentionedInReply::class,
NotifyUsersMentionedInReply::class,
],
ArticleWasSubmittedForApproval::class => [
SendNewArticleNotification::class,
],
ArticleWasApproved::class => [
SendArticleApprovedNotification::class,
],
EmailAddressWasChanged::class => [
RenewEmailVerificationNotification::class,
],
NotificationSent::class => [
StoreTweetIdentifier::class,
],
Registered::class => [
SendEmailVerificationNotification::class,
],
ReplyWasCreated::class => [
MarkLastActivity::class,
SendNewReplyNotification::class,
SubscribeUsersMentionedInReply::class,
NotifyUsersMentionedInReply::class,
],
ThreadWasCreated::class => [
SubscribeUsersMentionedInThread::class,
NotifyUsersMentionedInThread::class,
],
];

/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}
Loading