1. Go to this page and download the library: Download cleaniquecoders/shrinkr 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/ */
use CleaniqueCoders\Shrinkr\Models\Url;
use CleaniqueCoders\Shrinkr\Facades\Shrinkr;
$url = Url::find(1);
// Update the short URL with a new slug and expiry duration
$updatedUrl = Shrinkr::update($url, [
'custom_slug' => 'updated-slug',
'expiry_duration' => 120, // 2 hours from now
]);
echo $updatedUrl->shortened_url; // Outputs: https://yourdomain.com/updated-slug
namespace CleaniqueCoders\Shrinkr\Listeners;
use CleaniqueCoders\Shrinkr\Events\UrlAccessed;
use Illuminate\Support\Facades\Log;
class LogUrlAccess
{
public function handle(UrlAccessed $event)
{
$url = $event->url;
Log::info('URL accessed', [
'url_id' => $url->id,
'shortened_url' => $url->shortened_url,
'accessed_at' => now(),
]);
}
}
namespace CleaniqueCoders\Shrinkr\Listeners;
use CleaniqueCoders\Shrinkr\Events\UrlExpired;
use Illuminate\Support\Facades\Log;
class NotifyUrlExpired
{
public function handle(UrlExpired $event)
{
$url = $event->url;
Log::warning('URL expired', [
'url_id' => $url->id,
'shortened_url' => $url->shortened_url,
'expired_at' => now(),
]);
// Optionally, notify the user about the expired URL.
}
}