30
common/Workspaces/Actions/DeleteInviteNotification.php
Executable file
30
common/Workspaces/Actions/DeleteInviteNotification.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Workspaces\Actions;
|
||||
|
||||
use App\Models\User;
|
||||
use Common\Workspaces\Notifications\WorkspaceInvitation;
|
||||
use Common\Workspaces\WorkspaceInvite;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
|
||||
class DeleteInviteNotification
|
||||
{
|
||||
public function execute(WorkspaceInvite $invite, User $user): void
|
||||
{
|
||||
$notifications = $user
|
||||
->notifications()
|
||||
->where('type', WorkspaceInvitation::class)
|
||||
->limit(20)
|
||||
->get();
|
||||
|
||||
$notification = $notifications->first(function (
|
||||
DatabaseNotification $notification,
|
||||
) use ($invite) {
|
||||
return $notification->data['inviteId'] === $invite->id;
|
||||
});
|
||||
|
||||
if ($notification) {
|
||||
$notification->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user