1. Go to this page and download the library: Download ashallendesign/short-url 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/ */
ashallendesign / short-url example snippets
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->make();
$shortURL = $shortURLObject->default_short_url;
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->urlKey('custom-key')->make();
$shortURL = $shortURLObject->default_short_url;
// Short URL: https://webapp.com/short/custom-key
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits(false)->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackIPAddress()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackBrowser()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackBrowserVersion()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackOperatingSystem()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackOperatingSystemVersion()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackDeviceType()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->trackVisits()->trackRefererURL()->make();
use AshAllenDesign\ShortURL\Models\ShortURL;
use AshAllenDesign\ShortURL\Facades\ShortURL as ShortUrlBuilder;
$tenantId = 123;
$shortURL = ShortUrlBuilder::destinationUrl($url)
->beforeCreate(function (ShortURL $model): void {
$model->tenant_id = $tenantId;
})
->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')->singleUse()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('http://destination.com')->secure()->make();
// Destination URL: https://destination.com
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('http://destination.com?param1=test')->forwardQueryParams()->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('http://destination.com')->redirectStatusCode(302)->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->activateAt(\Carbon\Carbon::now()->addDay())->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->activateAt(\Carbon\Carbon::now()->addDay())
->deactivateAt(\Carbon\Carbon::now()->addDays(2))
->make();
use AshAllenDesign\ShortURL\Classes\Builder;
$shortURLObject = app(Builder::class)->destinationUrl('https://destination.com')
->generateKeyUsing(12345)
->make();
namespace App\Http\Controllers;
use ShortURL;
class Controller
{
public function index()
{
$shortURLObject = ShortURL::destinationUrl('https://destination.com')->make();
...
}
}
use AshAllenDesign\ShortURL\Classes\Builder;
$builder = app(Builder::class)->destinationUrl('https://destination.com');
if ($request->date('activation')) {
$builder = $builder->activateAt($request->date('activation'));
};
$shortURLObject = $builder->make();
use AshAllenDesign\ShortURL\Classes\Builder;
use Carbon\Carbon;
$shortURLObject = app(Builder::class)
->destinationUrl('https://destination.com')
->when(
$request->date('activation'),
function (Builder $builder, Carbon $activateDate): Builder {
return $builder->activateAt($activateDate);
},
)
->make();