Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for string events #67

Merged
merged 1 commit into from
Feb 7, 2024
Merged

Allow for string events #67

merged 1 commit into from
Feb 7, 2024

Conversation

LukeTowers
Copy link
Contributor

String events are especially useful for passing custom data to the listener. Consider the following:

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...
});

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...
});
```
@LukeTowers LukeTowers marked this pull request as ready for review August 4, 2023 22:56
@LukeTowers
Copy link
Contributor Author

@mpociot any feedback with this?

Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me. Thanks!

@simonhamp simonhamp merged commit 45b7ccf into NativePHP:main Feb 7, 2024
@LukeTowers LukeTowers deleted the patch-1 branch February 20, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants