palpalani/baylinks-laravel is a Laravel package for php/laravel framework sdk for baylinks..
It currently has 2 GitHub stars and 5.660 downloads on Packagist (latest version v0.5.0).
Install it with composer require palpalani/baylinks-laravel.
Discover more Laravel packages by palpalani
or browse all Laravel packages to compare alternatives.
Last updated
A modern, type-safe Laravel SDK for the BayLinks URL shortening platform
Features โข Installation โข Usage โข API Reference โข Contributing
This Laravel package provides an elegant, fluent interface to the BayLinks API - a powerful URL shortening and management platform for modern businesses. Built on top of Saloon PHP, this SDK offers type-safe request/response handling, robust error management, and seamless Laravel integration.
Install the package via Composer:
composer require palpalani/baylinks-laravel
Publish the configuration file:
php artisan vendor:publish --tag="baylinks-laravel-config"
This creates config/baylinks-laravel.php with the following structure:
return [
'server' => env('BAYLINKS_SERVER'),
'api' => [
'url' => 'api/v1',
'key' => env('BAYLINKS_API_KEY'),
'secret' => env('BAYLINKS_API_SECRET'),
],
];
Update your .env file:
BAYLINKS_SERVER=https://baylinks.io
BAYLINKS_API_KEY=your_api_key_here
BAYLINKS_API_SECRET=your_api_secret_here
use PalPalani\BayLinks\Facades\BayLinks;
$client = BayLinks::client();
$account = $client->accountDetails()->get('your_api_key');
use PalPalani\BayLinks\Facades\BayLinks;
$client = BayLinks::client();
$shortUrl = $client->createShortURL()->post('your_api_key', [
'destination' => 'https://example.com/very-long-url',
'domain' => 'custom.domain.com', // optional
]);
use PalPalani\BayLinks\Facades\BayLinks;
$client = BayLinks::client();
$bulkUrls = $client->createBulkURL()->post('your_api_key', [
'destination' => [
'https://example.com/page-1',
'https://example.com/page-2',
'https://example.com/page-3',
],
'domain' => 'custom.domain.com', // optional
'planet' => 'jupiter', // optional
'expire' => 0, // optional (0 = never expires)
'tag' => ['campaign' => 'summer-2024'], // optional metadata
]);
$client = BayLinks::client();
$response = $client->updateShortURLStatus()->post('your_api_key', [
'url_id' => 'abc123',
'status' => 'inactive',
]);
$client = BayLinks::client();
$visitRecords = $client->ShortUrlVisitRecord()->post('your_api_key', [
'url_id' => 'abc123',
'from_date' => '2024-01-01',
'to_date' => '2024-12-31',
]);
use PalPalani\BayLinks\Factory;
class UrlShortenerService
{
public function __construct(
private Factory $bayLinks
) {}
public function shortenUrl(string $url, string $apiKey): mixed
{
return $this->bayLinks
->createShortURL()
->post($apiKey, ['destination' => $url]);
}
}
use Saloon\Exceptions\Request\FatalRequestException;
use Saloon\Exceptions\Request\RequestException;
try {
$shortUrl = BayLinks::client()
->createShortURL()
->post('your_api_key', [
'destination' => 'https://example.com',
]);
} catch (FatalRequestException $e) {
// Handle fatal errors (network issues, timeouts, etc.)
Log::error('BayLinks fatal error: ' . $e->getMessage());
} catch (RequestException $e) {
// Handle API errors (validation, authentication, etc.)
Log::error('BayLinks API error: ' . $e->getMessage());
// Access response details
$statusCode = $e->getStatus();
$responseBody = $e->getResponse()->body();
}
use PalPalani\BayLinks\Facades\BayLinks;
$client = BayLinks::client();
// or
$client = BayLinks::factory();
| Method | Description | Parameters |
|--------|-------------|------------|
| accountDetails()->get($apiKey) | Retrieve account information | string $apiKey |
| Method | Description | Parameters |
|--------|-------------|------------|
| createShortURL()->post($apiKey, $data) | Create a single short URL | string $apiKey, array $data |
| createBulkURL()->post($apiKey, $data) | Create multiple short URLs | string $apiKey, array $data |
| updateShortURLStatus()->post($apiKey, $data) | Update URL status | string $apiKey, array $data |
| ShortUrlVisitRecord()->post($apiKey, $data) | Get visit analytics | string $apiKey, array $data |
[
'destination' => 'https://example.com/page', // required
'domain' => 'custom.domain.com', // optional
]
[
'destination' => [ // required (array of URLs)
'https://example.com/page-1',
'https://example.com/page-2',
],
'domain' => 'custom.domain.com', // optional
'planet' => 'jupiter', // optional
'expire' => 0, // optional (seconds, 0 = never)
'tag' => ['key' => 'value'], // optional (metadata)
]
Run the full test suite with Pest:
composer test
Run tests with coverage:
composer test-coverage
Run specific test file:
vendor/bin/pest tests/ExampleTest.php
Run tests with filtering:
vendor/bin/pest --filter=CanCreateShortUrl
Run PHPStan static analysis:
composer analyse
Format code with Laravel Pint:
composer format
This package uses Saloon PHP for HTTP client abstraction:
Saloon\Http\ConnectorAccountResource, CreateShortURLResource)Saloon\Http\Requestsrc/Requests/{Category}/src/Responses/{Category}/src/Resources/tests/See CLAUDE.md for detailed development guidelines.
This package uses GitHub Actions for automated testing and quality checks:
| Workflow | Purpose | Trigger | |----------|---------|---------| | Tests | Run Pest tests across PHP 8.3-8.4, Laravel 11-12, Ubuntu/Windows | Push, PR | | PHPStan | Static analysis at level 4 | Push, PR | | Code Coverage | Track test coverage with Codecov | Push, PR | | Security Scan | Composer audit, dependency review, SBOM generation | Push, PR, Weekly | | Code Style | Auto-fix with Laravel Pint | Push (branches only) | | PR Quality | Validate composer.json, check for debug statements | PR only |
All workflows use Composer caching for faster builds and concurrency controls to prevent redundant runs.
Make sure you've published the service provider:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
Verify your API key is correct and active:
// Test connection
try {
$account = BayLinks::client()->accountDetails()->get('your_api_key');
dump($account);
} catch (\Exception $e) {
echo $e->getMessage();
}
If you encounter SSL errors in development:
// In config/baylinks-laravel.php (development only!)
// Note: Never disable SSL verification in production
Please see CHANGELOG for recent changes and version history.
We welcome contributions! Here's how you can help:
git checkout -b feature/my-new-featuregit commit -am 'Add new feature'git push origin feature/my-new-featurecomposer analysecomposer format# Install dependencies
composer install
# Run tests
composer test
# Run static analysis
composer analyse
# Format code
composer format
composer test)composer analyse)composer format)If you discover any security-related issues, please email [email protected] instead of using the issue tracker. All security vulnerabilities will be promptly addressed.
The MIT License (MIT). Please see License File for more information.
Made with โค๏ธ by palPalani