store/app/Services/System/PushSubscriptionService.php

38 lines
893 B
PHP

<?php
namespace App\Services\System;
use App\Models\PushSubscription;
class PushSubscriptionService
{
/**
* Store or update a push subscription.
*
* @param array<string, mixed> $validated
*/
public function updateOrCreateSubscription(array $validated, int $userId): void
{
PushSubscription::updateOrCreate(
[
'user_id' => $userId,
'endpoint' => $validated['endpoint'],
],
[
'public_key' => $validated['publicKey'],
'auth_token' => $validated['authToken'],
]
);
}
/**
* Delete a push subscription.
*/
public function deleteSubscription(string $endpoint, int $userId): void
{
PushSubscription::where('user_id', $userId)
->where('endpoint', $endpoint)
->delete();
}
}