Skip to content

Update Notifications docs #83

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

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions resources/views/docs/desktop/1/the-basics/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,97 @@ Notification::title('Hello from NativePHP')
->show();
```

### Notification Reference

To keep track of different notifications, each notification gets a reference once created. You can manually set a reference using the `reference()` method.
By default, a unique ID is generated as the reference. Once the notification is shown, the reference is stored in the notification class.

```
$notification = Notification::title('Hello from NativePHP')->show();
$notification->reference; // <-- This property contains the reference
```

## Configuring Notifications

### Notification Title

You may set the notification's title using the `title()` method.

```php
Notification::title('Hello from NativePHP')
->show();
```

### Notification Reference

You can use the `reference()` method to set an event identifier and track which notification triggered a certain event.
This reference will be sent along with any event triggered by the notification. By default, the unique ID is generated as the reference.

```php
Notification::title('Hello from NativePHP')
->reference(Str::uuid())
->show();
```

### Notification Message

You may set the notification's message using the `message()` method.

```php
Notification::title('Hello from NativePHP')
->message('This is a detail message coming from your Laravel app.')
->show();
```

### Notification Reply

On macOS, you can allow the user to reply to a notification using the `hasReply()` method.

```php
Notification::title('Hello from NativePHP')
->hasReply()
->show();
```

The `hasReply()` method accepts a placeholder reply message as an argument.

```php
Notification::title('Hello from NativePHP')
->hasReply('This is a placeholder')
->show();
```

### Notification Actions

On macOS, you can add action buttons to a notification using the `addAction()` method.

```php
Notification::title('Hello from NativePHP')
->addAction('Click here')
->show();
```

You can call the `addAction()` method multiple times if you need to add multiple buttons.

```php
Notification::title('Hello from NativePHP')
->addAction('Button One')
->addAction('Button Two')
->show();
```

## Events

### `NotificationClicked`
The `Native\Laravel\Events\Notifications\NotificationClicked` event is dispatched when a user clicks on a notification.

### `NotificationClosed`
The `Native\Laravel\Events\Notifications\NotificationClosed` event is dispatched when a user closes a notification.

### `NotificationReply`
The `Native\Laravel\Events\Notifications\NotificationReply` event is dispatched when a user replies to a notification.

### `NotificationActionClicked`
The `Native\Laravel\Events\Notifications\NotificationActionClicked` event is dispatched when a user clicks an action button on a notification.

The `$index` references to the order of the buttons. The first button added has an index of `0`.