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
Documentation of New Features, Improvements in Package installation (#30)
- Added documentation for the new features
- Added a method to HasComments to fetch the current thread's users for
mentions
- Updated the installation command to back up the config file before
publishing a new one during upgrades
Copy file name to clipboardExpand all lines: README.md
+71-2Lines changed: 71 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,11 @@ Run the installation command and follow the prompts:
24
24
```bash
25
25
php artisan nested-comments:install
26
26
```
27
+
During the installation, you will be asked if you would like to publish and replace the config file.
28
+
This is important especially if you are upgrading the package to a newer version in which the config file structure has changed.
29
+
No worries, if you have customizations in your config file that you would like to keep, your current config file will be backed up to `config/nested-comments.php.bak` before the new config file is published.
30
+
31
+
You will also be asked if you would like to re-publish the package's assets. This is also important in case the package's styles and scripts have changed in the new version.
27
32
28
33
Adjust the configuration file as necessary, then run migrations.
29
34
@@ -210,8 +215,9 @@ $record = Conference::find(1); // Get your record from the database then,
210
215
```
211
216
212
217
### Mentions
213
-
The package uses Filament TipTap Editor which supports mentions. You can mention users in your comments by typing `@` followed by the user's name. The package will automatically resolve the user and send them a notification.
214
-
You can customize how to fetch mentions by changing the `.closures.getMentionsUsing` closure in the config file. Two sample methods have been included in the main class for getting all users in the DB or only users that have been mentioned in the current thread (default). Customize this however you wish.
218
+
The package uses Filament TipTap Editor which supports mentions. You can mention users in your comments by typing `@` followed by the user's name.
219
+
In the future, the package will support sending notifications to the mentioned users via database notifications if supported.
220
+
For more on how to customize the mentions, see the [Package Customization](#customize-how-to-get-the-mention-items) section below.
215
221
216
222
**Get only users mentioned in the current thread:**
217
223
@@ -327,7 +333,70 @@ The two components can be used anywhere, in resource pages, custom pages, action
327
333
328
334
## Package Customization
329
335
You can customize the package by changing most of the default values in the config file after publishing it.
336
+
Additionally, you can customize how the package interacts with your models by overriding some methods in your commentable model.
337
+
338
+
### Customize how to get the Comment Author's Name
339
+
You can customize how to get the comment author's name by overriding the `getUserName` method in your commentable model.
340
+
By default, the package uses the `name` attribute of the user model, but you can change this to any other attribute or method that returns a string.
341
+
342
+
This name will be displayed in the comment card, and it will also be used to mention the user in the comment text.
343
+
344
+
```php
345
+
// e.g in your Post model or any other model that uses the HasComments trait
346
+
use Coolsam\NestedComments\Traits\HasComments;
347
+
348
+
public function getUserName(Model|Authenticatable|null $user): string
You can customize the user's avatar by overriding the `getUserAvatar` method in your commentable model.
356
+
357
+
By default, the package uses [ui-avatars](https://ui-avatars.com) to generate the avatar based on the user's name, but you can change this to any other method that returns a URL to the user's avatar image.
358
+
359
+
```php
360
+
// e.g in your Post model or any other model that uses the HasComments trait
361
+
use Coolsam\NestedComments\Traits\HasComments;
330
362
363
+
public function getUserAvatar(Model|Authenticatable|string|null $user): ?string
364
+
{
365
+
// return 'https://yourprofile.url.png';
366
+
return $user->getAttribute('profile_url') // get your user's profile url here, assuming you have defined it in your user's model.
367
+
}
368
+
```
369
+
370
+
### Customize how to get the Mention Items
371
+
You can customize how to get the mention items by overriding and changing the `getMentionsQuery` method in your commentable model.
372
+
By default, the package gets mention items from all users in your database.
373
+
For example, if you would only like to mention users who have commented on the current thread, you can do so by changing the method to return only those users.
374
+
There is a handy method included in the default class to achieve this. Alternatively, you can go wild and mention fruits instead of users! The choice is within your freedom.
375
+
376
+
```php
377
+
// e.g in your Post model or any other model that uses the HasComments trait
378
+
use Coolsam\NestedComments\Traits\HasComments;
379
+
380
+
public function getMentionsQuery(string $query): Builder
0 commit comments