PHP code example of laracrafts / laravel-url-shortener

1. Go to this page and download the library: Download laracrafts/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/ */

    

laracrafts / laravel-url-shortener example snippets


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

$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(...);
    }
}

public function boot(ShortenerManager $shorteners)
{
    $shorteners->extend('my_driver', function ($app, $config) {
       // Return your driver instance here
    });
}