Skip to content

Instantly share code, notes, and snippets.

@HeadStudios
Created May 19, 2023 00:18
Show Gist options
  • Save HeadStudios/b2ffd252e82be5f80a2b0085bedf7057 to your computer and use it in GitHub Desktop.
Save HeadStudios/b2ffd252e82be5f80a2b0085bedf7057 to your computer and use it in GitHub Desktop.
<?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use AshAllenDesign\ShortURL\Events\ShortURLVisited;
use App\Models\CampaignContact;
use App\Models\Contact;
use App\Hydraulics\AirBooker;
use Illuminate\Support\Carbon;
use App\Models\User;
use App\Notifications\CustomNovaNotification;
use Laravel\Nova\Notifications\NovaNotification;
class PhoneMessageLinkClicked
{
/**
* Create the event listener.
*
* @return void
*/
public $airbooker;
public function __construct()
{
//$this->airbooker = new AirBooker;
}
/**
* Handle the event.
*
* @param \App\Events\ShortURLVisited $event
* @return void
*/
public function handle(ShortURLVisited $event)
{
$shortURL = $event->shortURL;
$message = CampaignContact::where('shortlink', 'like', '%'.$shortURL->url_key.'%')->first();
$user = User::find(1);
if($message) {
//
$message->click();
$contact = Contact::find($message->contacts_id);
$email = $contact->email;
// increment the score of the contact model by 3
$contact->score += 3;
$contact->save();
$contact = Contact::where('email', $email)->first();
if (!$contact) {
return response('Contact not found', 404);
}
$user->notify(
CustomNovaNotification::make()
->message($contact->email.' has clicked an SMS')
->icon('download')
->type('info')
->cid($contact->id)
);
//
}
dump("Gift clicked now");
if ($shortURL->contacts && $shortURL->gift && $shortURL->gift->giftType) {
$contact = $shortURL->contacts->first();
$email = $contact->email ?? 'No email';
dump("Email: ".$email);
$permalink = $shortURL->gift->giftType->permalink ?? 'No permalink';
dump("Permalink: ".$permalink);
$user->notify(
CustomNovaNotification::make()
->message($email . ' has clicked the ' . $permalink . ' gift!')
->icon('cursor-click')
->type('info')
->cid($contact->id)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment