diff --git a/src/Contracts/HasDevices.php b/src/Contracts/HasDevices.php index 5a5e0eb..69df574 100644 --- a/src/Contracts/HasDevices.php +++ b/src/Contracts/HasDevices.php @@ -13,4 +13,9 @@ interface HasDevices * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function devices(); + + /** + * @return string[] + */ + public function deviceTokens(): array; } diff --git a/src/Models/Concerns/WithDevices.php b/src/Models/Concerns/WithDevices.php index 8f55208..443ff13 100644 --- a/src/Models/Concerns/WithDevices.php +++ b/src/Models/Concerns/WithDevices.php @@ -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(); + } }