where('user_ref', strtolower((string) $user->email)) ->update(['user_ref' => $user->public_id]); try { $access = $this->identity->teamAccess($user->public_id); } catch (\Throwable) { return; } foreach ($access as $grant) { if (($grant['self'] ?? false) || ($grant['full_access'] ?? false)) { continue; } $apps = (array) ($grant['apps'] ?? []); if (! in_array('pos', $apps, true)) { continue; } $meta = (array) data_get($grant, 'metadata.pos', []); PosMember::updateOrCreate( [ 'owner_ref' => (string) ($grant['account'] ?? $user->public_id), 'user_ref' => $user->public_id, ], [ 'role' => (string) ($meta['role'] ?? PosMember::ROLE_CASHIER), 'location_id' => $meta['location_id'] ?? null, ], ); } } }