PHP code example of afurgeri / laravel-short-links
1. Go to this page and download the library: Download afurgeri/laravel-short-links 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/ */
namespace App\Listeners;
use App\Models\Campaign;
use Illuminate\Contracts\Queue\ShouldQueue;
use Modules\ShortLinks\Events\LinkVisited;
final class IncrementCampaignClicks implements ShouldQueue
{
public function handle(LinkVisited $event): void
{
if ($event->campaignId === null) {
return;
}
Campaign::query()
->whereKey($event->campaignId)
->increment('clicks_count');
}
}
use App\Listeners\IncrementCampaignClicks;
use Illuminate\Support\Facades\Event;
use Modules\ShortLinks\Events\LinkVisited;
Event::listen(LinkVisited::class, IncrementCampaignClicks::class);