32 lines
737 B
PHP
32 lines
737 B
PHP
<?php
|
|
|
|
namespace App\Services\System;
|
|
|
|
use App\Models\PushSubscription;
|
|
|
|
class PushSubscriptionService
|
|
{
|
|
|
|
public function updateOrCreateSubscription(array $validated, int $userId): void
|
|
{
|
|
PushSubscription::updateOrCreate(
|
|
[
|
|
'user_id' => $userId,
|
|
'endpoint' => $validated['endpoint'],
|
|
],
|
|
[
|
|
'public_key' => $validated['publicKey'],
|
|
'auth_token' => $validated['authToken'],
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
public function deleteSubscription(string $endpoint, int $userId): void
|
|
{
|
|
PushSubscription::where('user_id', $userId)
|
|
->where('endpoint', $endpoint)
|
|
->delete();
|
|
}
|
|
}
|