PHP code example of binary-cats / laravel-url-shortener

1. Go to this page and download the library: Download binary-cats/laravel-url-shortener library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

binary-cats / laravel-url-shortener example snippets


'providers' => [
   ...
   BinaryCats\UrlShortener\UrlShortenerServiceProvider::class,
   ...
],

return [

    'default' => env('URL_SHORTENER_DRIVER', 'tiny_url'),

    'shorteners' => [

        'bit_ly' => [
            'driver' => 'bit_ly',
            'domain' => env('URL_SHORTENER_PREFIX', 'bit.ly'),
            'token' => env('URL_SHORTENER_API_TOKEN'),
        ],

        'firebase' => [
            'driver' => 'firebase',
            'prefix' => env('URL_SHORTENER_PREFIX'),
            'token' => env('URL_SHORTENER_API_TOKEN'),
            'suffix' => env('URL_SHORTENER_STRATEGY', 'UNGUESSABLE'),
        ],

        'is_gd' => [
            'driver' => 'is_gd',
            'base_uri' => 'https://is.gd',
            'statistics' => env('URL_SHORTENER_ANALYTICS', false),
        ],

        'ouo_io' => [
            'driver' => 'ouo_io',
            'token' => env('URL_SHORTENER_API_TOKEN'),
        ],

        'polr' => [
            'driver' => 'polr',
            'prefix' => env('URL_SHORTENER_PREFIX'),
            'token' => env('URL_SHORTENER_API_TOKEN'),
        ],

        'shorte_st' => [
            'driver' => 'shorte_st',
            'token' => env('URL_SHORTENER_API_TOKEN'),
        ],

        'tiny_url' => [
            'driver' => 'tiny_url',
        ],

        'v_gd' => [
            'driver' => 'is_gd',
            'base_uri' => 'https://v.gd',
            'statistics' => env('URL_SHORTENER_ANALYTICS', false),
        ],
    ],
];

$shortener = app('url.shortener');
// or...
$shortener = url()->shortener();

// This will return your shortened URL as a string
$shortener->shorten(...);

// This will return a promise which will resolve to your shortened URL
$shortener->shortenAsync(...);

// You can also call shortening from Laravel's url component directly
url()->shorten(...);

// or...
app('url')->shorten(...);

// or even...
app('url.shortener')->shorten(...);

class MyController extends Controller
{
    public function myFunction(ShortenerManager $shortener)
    {
        $shortener->shorten(...);
    }
}

use BinaryCats\UrlShortener\UrlShortenerManager;

public function boot(UrlShortenerManager $shorteners)
{
    $shorteners->extend('local', function ($app, $config) {
        return new LocalUrlShortener($app, $config);
    });
}
bash
php artisan vendor:publish --provider=BinaryCats\\UrlShortener\\UrlShortenerServiceProvider