Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat: optimize the use the user_devices.token[]
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Dec 25, 2023
1 parent ebeb471 commit f44619f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Contracts/HasDevices.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ interface HasDevices
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function devices();

/**
* @return string[]
*/
public function deviceTokens(): array;
}
16 changes: 16 additions & 0 deletions src/Models/Concerns/WithDevices.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ public function devices()
{
return $this->hasMany(UserDevice::class);
}

/**
* {@inheritdoc}
*/
public function deviceTokens(): array
{
static $tokens;

if ($tokens) {
return $tokens;
}

$this->loadMissing('devices');

return $tokens = $this->devices->pluck('token')->toArray();
}
}

0 comments on commit f44619f

Please sign in to comment.