PHP code example of codeofdigital / laravel-url-shortener
1. Go to this page and download the library: Download codeofdigital/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/ */
codeofdigital / laravel-url-shortener example snippets
$shortUrl = new UrlShortener();
$shortUrl->shorten('https://example.com');
$shortener = app('url.shortener');
// or ...
$shortener = url()->shortener();
use CodeOfDigital\LaravelUrlShortener\Facades\UrlShortener;
$shortUrl = UrlShortener::shorten('https://example.com');
use CodeOfDigital\LaravelUrlShortener\UrlShortener;
class MyController extends Controller
{
public function myFunction(UrlShortener $shortener)
{
$shortener->shorten('https://example.com');
}
}
// This will set and create the driver instance
$shortener->driver('own-driver');
// This will return shortened URL in string
$shortener->shorten('https://example.com');
// This will return a promise object which can be used to resolve and retrieve shortened URL later on
$shortener->shortenAsync('https://example.com');
// Methods can be called from Laravel URL components
url()->shorten('https://example.com');
// Or
app('url.shortener')->shorten('https://example.com');
// Methods can be chained as well
$shortener->driver('own-driver')->shorten('https://example.com');