Files
ladill-link/app/Services/Link/PlatformLinkCatalogClient.php
T
isaaccladandCursor f1fe749934
Deploy Ladill Link / deploy (push) Successful in 29s
Aggregate ladl.link slugs from all platform apps in the link list.
Sync QR and storefront short codes from sibling apps via a platform catalog API so My Links shows every ladl.link URL in one place.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 13:26:16 +00:00

50 lines
1.2 KiB
PHP

<?php
namespace App\Services\Link;
use Illuminate\Support\Facades\Http;
/**
* Fetches ladl.link slugs created in other Ladill apps from the platform catalog API.
*/
class PlatformLinkCatalogClient
{
private function base(): string
{
$platform = rtrim((string) config('app.platform_url', 'https://ladill.com'), '/');
return $platform.'/api/link-catalog';
}
private function token(): string
{
return (string) (config('billing.api_key') ?? '');
}
/** @return list<array<string, mixed>> */
public function linksForUser(string $publicId): array
{
if ($this->token() === '') {
return [];
}
try {
$response = Http::withToken($this->token())
->acceptJson()
->timeout(12)
->get($this->base().'/links', ['user' => $publicId]);
if (! $response->successful()) {
return [];
}
return array_values(array_filter(
(array) ($response->json('links') ?? []),
fn ($row) => is_array($row) && filled($row['slug'] ?? null),
));
} catch (\Throwable) {
return [];
}
}
}