DeviceTokenService.php 685 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Services;
  3. use App\Models\DeviceToken;
  4. use Illuminate\Support\Facades\Auth;
  5. class DeviceTokenService
  6. {
  7. public function register(array $data): DeviceToken
  8. {
  9. return DeviceToken::updateOrCreate(
  10. ['token' => $data['token']],
  11. [
  12. 'user_id' => Auth::id(),
  13. 'platform' => $data['platform'],
  14. 'app_type' => $data['app_type'],
  15. 'active' => true,
  16. ]
  17. );
  18. }
  19. public function remove(string $token): void
  20. {
  21. DeviceToken::where('token', $token)
  22. ->where('user_id', Auth::id())
  23. ->update(['active' => false]);
  24. }
  25. }