8000 Allow for string events · NativePHP/laravel@45b7ccf · GitHub
[go: up one dir, main page]

Skip to content

Commit 45b7ccf

Browse files
LukeTowerssimonhamp
authored andcommitted
Allow for string events
String events are especially useful for passing custom data to the listener. Consider the following: ```php use Native\Laravel\Client\Client; use Native\Laravel\Notification; // Send a notification with a custom event $client = new Client(); $notification = new Notification($client); $articleId = 1; $notification->title('EXTRA EXTRA READ ALL ABOUT IT') ->message('You should totally click this) ->event('notification.clicked.newArticle' . $articleId) ->show(); // Listen to the notification Event::listen('notification.clicked.newArticle.*', function ($event) { $event = explode('.', $event) $articleId = array_last($event); // do stuff... }); ```
1 parent e9a7532 commit 45b7ccf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Http/Controllers/DispatchEventFromAppController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ class DispatchEventFromAppController
99
publ 8000 ic function __invoke(Request $request)
1010
{
1111
$event = $request->get('event');
12-
if (class_exists($event)) {
13-
$event = new $event(...$request->get('payload', []));
12+
$payload = $request->get('payload', []);
1413

14+
if (class_exists($event)) {
15+
$event = new $event(...$payload);
1516
event($event);
17+
} else {
18+
event($event, $payload);
1619
}
1720

1821
return response()->json([

0 commit comments

Comments
 (0)
0