-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create listeners and events (#62)
- Loading branch information
Showing
7 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Name; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class Favorited | ||
{ | ||
use Dispatchable, SerializesModels; | ||
|
||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct( | ||
public User $user, | ||
public Name $favorited | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Models\User; | ||
use Illuminate\Auth\Events\Authenticated as AuthenticatedEvent; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Pirsch\Facades\Pirsch; | ||
|
||
class Authenticated implements ShouldQueue | ||
{ | ||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(AuthenticatedEvent $event): void | ||
{ | ||
if ($event->user instanceof User) { | ||
Pirsch::track('Authenticated', [ | ||
'UserId' => $event->user->id, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Determine whether the listener should be queued. | ||
*/ | ||
public function shouldQueue(AuthenticatedEvent $event): bool | ||
{ | ||
return $event->user instanceof User && ! $event->user->is_administrator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\Favorited as FavoritedEvent; | ||
use Pirsch\Facades\Pirsch; | ||
|
||
class Favorited | ||
{ | ||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(FavoritedEvent $event): void | ||
{ | ||
Pirsch::track('Favorited', [ | ||
'UserId' => $event->user->id, | ||
'Name' => $event->favorited->name, | ||
'Id' => $event->favorited->id, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Models\User; | ||
use Illuminate\Auth\Events\Registered as RegisteredEvent; | ||
use Pirsch\Facades\Pirsch; | ||
|
||
class Registered | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(RegisteredEvent $event) | ||
{ | ||
if ($event->user instanceof User) { | ||
Pirsch::track('Registered', [ | ||
'UserId' => $event->user->id, | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters