The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Hide the php SDK guide
Kiran K1e2669fbbda6
diff --git a/apps/docs/mint.json b/apps/docs/mint.jsonindex 278509fcf0..54d9a4b6a1 100644--- a/apps/docs/mint.json+++ b/apps/docs/mint.json@@ -86,10 +86,6 @@{"group": "Ruby","pages": ["quickstart/ruby", "quickstart/rails", "quickstart/sinatra"]- },- {- "group": "PHP",- "pages": ["quickstart/php", "quickstart/laravel"]}]},diff --git a/apps/docs/quickstart/php.mdx b/apps/docs/quickstart/php.mdxindex 94ebcd7d2b..6df2744702 100644--- a/apps/docs/quickstart/php.mdx+++ b/apps/docs/quickstart/php.mdx@@ -15,22 +15,134 @@ To install the Dub PHP SDK, run the following command:composer require dub/dub-php```+Initialize the Dub PHP SDK by creating a new instance of the `Dub` class.++```php+require 'vendor/autoload.php';++use \Dub;+use Dub\Models\Components;+use Dub\Models\Operations;++$security = new Components\Security();+$security->token = 'DUB_API_KEY';++$dub = Dub\Dub::builder()+ ->setWorkspaceId('ws_clugls3...')+ ->setSecurity($security)+ ->build();+```+## 3. Create link+Let's create a short link using the Dub Node.js SDK.++```php index.php+$requestBody = new Operations\CreateLinkRequestBody();+$requestBody->url = 'https://google.com';++$response = $dub->links->create($requestBody);++echo $response->shortLink;+```++<Accordion title="Full list of available attributes for the Link model">+ <LinkArguments />+</Accordion>++## 3a. Create link with `externalId`++Optionally, you can also pass an `externalId` field which is a unique identifier for the link in your own database to associate it with the link in Dub's system.++```php index.php+$requestBody = new Operations\CreateLinkRequestBody();+$requestBody->url = 'https://google.com';+$requestBody->externalId = '12345';++$response = $dub->links->create($requestBody);++echo $response->shortLink;+```+## 4. Upsert link+Dub Node.js SDK provides a method to create or update a link so you don't have to worry about checking if the link already exists.++```php index.php+// Update the link if same URL already exists or create a new link+$requestBody = new Operations\UpsertLinkRequestBody();+$requestBody->url = 'https://google.com';++$response = $dub->links->upsert($requestBody);++echo $response->shortLink;+```+## 5. Update link+Let's update an existing link using the Dub Node.js SDK.++You can do that in two ways:++- Using the link's `linkId` in Dub's system.+- Using the link's `externalId` in your own database (prefixed with `ext_`).++```php index.php+// Update a link by its linkId+$requestBody = new Operations\UpdateLinkRequest();+$requestBody->linkId = 'clv3o9p9q000au1h0mc7r6l63'+$requestBody->url = 'https://google.uk'; // new URL++$response = $dub->links->update($requestBody);++// Update a link by its externalId+$requestBody = new Operations\UpdateLinkRequest();+$requestBody->externalId = 'ext_12345'+$requestBody->url = 'https://google.uk'; // new URL++$response = $dub->links->update($requestBody);++echo $response->shortLink;+```+## 6. Retrieve analytics for link+Dub allows you to retrieve analytics for a link using the Dub Node.js SDK.++```php index.php+// Retrieve the timeseries analytics for the last 7 days for a link+$request = new Operations\RetrieveAnalyticsRequest();+$request->linkId = 'clv3o9p9q000au1h0mc7r6l63';+$request->interval = Operations\Interval::Ninetyd;+$request->groupBy = Operations\GroupBy::Timeseries;++$response = $dub->analytics->retrieve($request);++echo $response;+```++Simliarly, you can retrieve analytics for a link using the `externalId` field.++```php index.php+// Retrieve the timeseries analytics for the last 7 days for a link+$request = new Operations\RetrieveAnalyticsRequest();+$request->externalId = 'ext_12345';+$request->interval = Operations\Interval::Ninetyd;+$request->groupBy = Operations\GroupBy::Timeseries;++$response = $dub->analytics->retrieve($request);++echo $response;+```+## 7. Examples<CardGroup cols={2}><Card- title="PHP Example"+ title="Express Example"icon="arrow-up-right-from-square"- href="https://github.com/dubinc/examples"+ href="https://github.com/dubinc/examples/tree/main/php">See the full example on GitHub.</Card>-</CardGroup>+</CardGroup>\ No newline at end of file