PHP code example of bradietilley / laravel-shortify

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

    

bradietilley / laravel-shortify example snippets


$shortUrl = Shortify::make()->shorten($longUrl)->url; // https://app.com/s/Ws4BYCVLDDDh
$shortUrl = Shortify::url($longUrl)->url; //             https://app.com/s/5wHiKrKx5xV1

public function handle(Shortify $shortify): void
{
    $url = $shortify->shorten($this->invoice->getSignedUrl());

    echo $url->url; // https://app.com/s/xpLurjDkBATw
}

$shortUrl = Shortify::make()->shorten($longUrl, expiry: now()->addDay());
$shortUrl = Shortify::url($longUrl, expiry: now()->addDay());

$url = Shortify::url($longUrl);
$url->original_url; // same as $longUrl

$url = Shortify::url($longUrl);
$url->url; // https://app.com/s/xpLurjDkBATw

$url = ShortifyUrl::findByCode('my-short-url');

$url->visits; // Collection<ShortifyVisit>

namespace App\Support;

class Shortify extends \BradieTilley\Shortify\Shortify
{
    public function generateCode(ShortifyUrl $url): string
    {
        return Carbon::now()->format('Ymd').'-'.Str::random(6);
    }
}

$this->app->bind(\BradieTilley\Shortify\Shortify::class, \App\Support\Shortify::class);

echo Shortify::url($longUrl)->url; // 20241026-TWrCmX