PHP code example of richard-roman / short-links-qr

1. Go to this page and download the library: Download richard-roman/short-links-qr 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/ */

    

richard-roman / short-links-qr example snippets


$shortLink = ShortLinks::create(
    urlDestino: 'https://example.com/recurso',
    titulo: 'Demo',
    codigo: 'K7MNP2WX', // normalizado a minúsculas; debe cumplir route_pattern
);

// Marca el link como inactivo e invalida su caché de redirección.
ShortLinks::deactivate('k7mn2wxp');

// A partir de este momento GET /l/k7mn2wxp retorna 404.

// Rotación con código auto-generado
$nuevoLink = ShortLinks::rotate('codigo-viejo');

// Rotación con código manual
$nuevoLink = ShortLinks::rotate('codigo-viejo', 'codigo-nuevo');

// El nuevo link hereda: urlDestino, entidadTipo, entidadId, titulo, creadoPorId
echo $nuevoLink->codigo; // "codigo-nuevo"

use RichardRoman\ShortLinks\Laravel\Facades\ShortLinks;

$shortLink = ShortLinks::create(
    urlDestino: 'https://www.youtube.com/watch?v=abc123',
    titulo: 'Video demo',
    entidadTipo: 'entregable',
    entidadId: $entregableId,
    creadoPorId: auth()->id(),
);

$existente = ShortLinks::findByEntity('entregable', $entregableId);

use App\ShortLinks\Resolvers\EntregableEntityResolver;
use App\ShortLinks\Resolvers\ProyectoEntityResolver;

$this->app->tag([
    ProyectoEntityResolver::class,
    EntregableEntityResolver::class,
], 'short-links.entity-resolvers');

public function supports(string $entidadTipo): bool;
public function resolveUrl(string $entidadId): ?string;
bash
php artisan migrate
bash
php artisan vendor:publish --tag=short-links-config