### Install Laravel Dub and publish config Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Install the package with Composer, then optionally publish the configuration file using the dub-config tag. ```bash composer require jeffersongoncalves/laravel-dub ``` ```bash php artisan vendor:publish --tag="dub-config" ``` -------------------------------- ### Run static analysis with composer analyse Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Run static analysis with PHPStan. ```bash composer analyse ``` -------------------------------- ### Format code with composer format Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Run code formatting. ```bash composer format ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Run the test suite. ```bash composer test ``` -------------------------------- ### Configure Laravel Dub in config/dub.php Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Configuration options for the package: api_key, api_url (default https://api.dub.co), and timeout (default 8 seconds). ```php // config/dub.php return [ 'api_key' => env('DUB_API_KEY'), 'api_url' => env('DUB_API_URL', 'https://api.dub.co'), 'timeout' => (int) env('DUB_TIMEOUT', 8), ]; ``` -------------------------------- ### Set DUB_API_KEY in .env Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Add your Dub API key to the .env file. Create an API key from your Dub workspace settings. ```env DUB_API_KEY=dub_xxxxxxxxxxxxxxxxxxxx ``` -------------------------------- ### Use DubClient for link management and analytics Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Basic usage of the DubClient static methods for link management and analytics. Methods return null/false on ordinary failures, and throw DubRateLimitException on rate limits. ```php use JeffersonGoncalves\Dub\DubClient; use JeffersonGoncalves\Dub\Exceptions\DubRateLimitException; // Create a link $link = DubClient::createLink([ 'url' => 'https://example.com', 'domain' => 'dub.sh', ]); // List links $links = DubClient::listLinks(['domain' => 'dub.sh']); // Get a link by domain/key or linkId/externalId $link = DubClient::getLink(['domain' => 'dub.sh', 'key' => 'abc123']); // Update a link $link = DubClient::updateLink('link_1234', ['url' => 'https://example.com/updated']); // Delete a link $deleted = DubClient::deleteLink('link_1234'); // Bulk create links $links = DubClient::bulkCreateLinks([ ['url' => 'https://example.com/a'], ['url' => 'https://example.com/b'], ]); // Analytics $analytics = DubClient::analytics(['domain' => 'dub.sh', 'key' => 'abc123']); $byCountry = DubClient::analyticsByCountry(['domain' => 'dub.sh', 'key' => 'abc123']); $byDevice = DubClient::analyticsByDevice(['domain' => 'dub.sh', 'key' => 'abc123']); ``` -------------------------------- ### Handle DubRateLimitException Source: https://github.com/jeffersongoncalves/laravel-dub/blob/main/README.md Handle rate limits by catching DubRateLimitException and backing off for the retryAfter seconds. ```php try { $links = DubClient::listLinks(); } catch (DubRateLimitException $e) { // Back off for $e->retryAfter seconds (queue jobs can release($e->retryAfter)). } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.