You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/content/docs/messages.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,8 @@ $sender = $message->sender; // Returns the participant who sent the message
81
81
```
82
82
This returns the `ChatParticipant` morph model, which represents the participant who sent the message. This is by design, letting you work with a unified interface for all participants, regardless of their underlying model.
83
83
84
+
Remember that not all messages have a sender. For example, system messages do not have a sender, so the `sender` relationship may return `null` in those cases.
85
+
84
86
### Returning the actual model that sent the message
85
87
This will return an instance of the `ChatParticipant` model, which you can then use to get the actual model that sent the message (e.g., a User model).
Copy file name to clipboardExpand all lines: docs/src/content/docs/notifications.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ foreach ($notifiableParticipants as $participant) {
38
38
## Default New Message Notification
39
39
The default notification is `\Mmedia\LeChat\Notifications\NewMessage::class`, which will send a notification to each of the participants personal channels when a new message is created, except the sender of the message, via the [Broadcasting](/broadcasting) channel.
40
40
41
-
If you have `WebPush` channel installed, the notification will automatically be sent via web-push if the participant is not connected to the chatroom via sockets. This is useful for sending notifications to users who are not currently online in the chatroom.
41
+
If you have the `WebPush` channel installed, the notification will automatically be sent via web-push if the participant is not connected to the chatroom via sockets. This is useful for sending notifications to users who are not currently online in the chatroom.
42
42
43
43
### Difference from the event broadcast
44
44
The `NewMessage` notification is sent to the personal channel of each participant, while the event is broadcasted to the chatroom presence channel. This means that the notification will be sent to each participant individually, while the event is sent to the chatroom as a whole.
Copy file name to clipboardExpand all lines: docs/src/content/docs/participants.md
+20-17Lines changed: 20 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,25 @@ If you want to use a different date range, you can use the `whereHasUnreadMessag
110
110
$users = User::whereHasUnreadMessages(7, true)->get(); // unread messages sent in the last 7 days, including system messages
111
111
```
112
112
113
+
## Getting a personal chatroom
114
+
You can retrieve a "personal chatroom" for a participant, which is a chatroom that only contains that participant. This is useful for sending notifications or system messages that are not part of any other chatroom.
115
+
116
+
```php
117
+
$personalChatroom = $teacher->getOrCreatePersonalChatroom(); // Will return the first chatroom that only contains the teacher as a participant
118
+
```
119
+
120
+
If you want to configure the personal chatroom if its created, you can pass an array of attributes to the `getOrCreatePersonalChatroom` method:
121
+
122
+
```php
123
+
$teacher->getOrCreatePersonalChatroom([
124
+
'name' => 'My Personal Chatroom',
125
+
'description' => 'This is my personal chatroom for notifications and system messages, and sometimes notes.',
126
+
'metadata' => [
127
+
'foo' => 'bar', // Optional metadata for the personal chatroom
128
+
],
129
+
]);
130
+
```
131
+
113
132
## Working with the intermediate morph model
114
133
Le Chat uses an intermediate morph model called `ChatParticipant` to manage the relationships between your chattable models and the chatrooms they participate in.
115
134
@@ -118,7 +137,7 @@ This model represents a participant in a chatroom and contains additional inform
118
137
The intermediate model is more than just a pivot table; it allows you to have a unified representation of all participants in a chatroom, separate from your own models. This allows you to maximise the separation of concerns between your application logic and the chat functionality.
119
138
120
139
### Getting the intermediate model from your model
121
-
You can retrieve the `ChatParticipant` instance for a specific participant using the `chatParticipant` method on your model:
140
+
You can retrieve the `ChatParticipant` instance for a specific participant using the `asParticipantIn` method on your model:
@@ -172,20 +191,4 @@ $chatrooms = Chatroom::hasParticipant([$teacher, $chatParticipant]); // Will ret
172
191
The model itself also implements the `ChatParticipantInterface`, and uses the trait, so you can use it in the same way as your own models:
173
192
```php
174
193
$chatParticipant->sendMessageTo($student, 'Hello from the chat participant!');
175
-
```
176
-
177
-
## Getting a personal chatroom
178
-
You can retrieve a "personal chatroom" for a participant, which is a chatroom that only contains that participant. This is useful for sending notifications or system messages that are not part of any other chatroom.
179
-
180
-
```php
181
-
$personalChatroom = $teacher->getOrCreatePersonalChatroom(); // Will return the first chatroom that only contains the teacher as a participant
182
-
```
183
-
184
-
If you want to configure the personal chatroom if its created, you can pass an array of attributes to the `getOrCreatePersonalChatroom` method:
185
-
186
-
```php
187
-
$teacher->getOrCreatePersonalChatroom([
188
-
'name' => 'My Personal Chatroom',
189
-
'description' => 'This is my personal chatroom for notifications and system messages, and sometimes notes.',
Copy file name to clipboardExpand all lines: docs/src/content/docs/routing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ description: Documentation for Le Chat routing.
7
7
Le Chat provides a powerful set of API routes for managing chatrooms and sending messages. These routes are automatically registered by the package.
8
8
9
9
## Configuration
10
-
Routes are enabled by default. If you publish the package configuration file, you can customize the middleware and prefix used for the API routes in `config/chat.php`:
10
+
Routes are enabled by default. You can customize the middleware and prefix used for the API routes in `config/chat.php`:
0 commit comments