Skip to content

Commit 93c09b2

Browse files
authored
Documentation: Added documentation for the Filament components (#23)
- Added documentation for Infolist Entry - Added documentation for the Comments Widget - Added documentation for the Comments Table Action - Added documentation for teh Comments Header Action
2 parents c7d8bae + 0a3124c commit 93c09b2

File tree

4 files changed

+186
-15
lines changed

4 files changed

+186
-15
lines changed

README.md

Lines changed: 178 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
This package allows you to incorporate comments and replies in your Filament forms, infolists, pages, widgets etc, or even simply in your livewire components. Comment replies can be nested as deep as you want, using the Nested Set data structure. Additionally, the package comes with a Reactions feature to enable your users to react to any of your models (e.g comments or posts) with selected emoji reactions.
1212

13-
![image](https://github.com/user-attachments/assets/e4ff32b3-0eb9-4ad4-8edb-de91b1940e13)
14-
13+
![image](https://github.com/user-attachments/assets/2900e2a4-9ad2-40e2-8819-2650b6d70803)
1514

1615
## Installation
1716

@@ -21,13 +20,6 @@ You can install the package via composer:
2120
composer require coolsam/nested-comments
2221
```
2322

24-
You can publish and run the migrations with:
25-
26-
```bash
27-
php artisan vendor:publish --tag="nested-comments-migrations"
28-
php artisan migrate
29-
```
30-
3123
Run the installation command and follow the prompts:
3224

3325
```bash
@@ -38,11 +30,186 @@ Adjust the configuration file as necessary, then run migrations.
3830

3931
`That's it! You are now ready to add nested comments
4032

41-
## Usage
42-
**WIP**
33+
## Usage: Comments
34+
At the very basic level, this package is simply a Livewire Component that takes in a model record which is commentable. Follow the following steps to prepare your model to be commentable or reactable:
35+
1. Add the `HasComments` trait to your model
4336
```php
4437

38+
use Coolsam\NestedComments\Traits\HasComments;
39+
40+
class Conference extends Model
41+
{
42+
use HasComments;
43+
44+
// ...
45+
}
46+
47+
```
48+
2. If you would like to be able to react to your model directly as well, add the `HasReactions` trait to your model
49+
```php
50+
use Coolsam\NestedComments\Traits\HasReactions;
51+
52+
class Conference extends Model
53+
{
54+
use HasReactions;
55+
56+
// ...
57+
}
4558
```
59+
3. You can now access the comments and reactions of your model in the following ways
60+
61+
### Using the Comments Infolist Entry
62+
63+
```php
64+
public static function infolist(Infolist $infolist): Infolist
65+
{
66+
return $infolist
67+
->schema([
68+
Section::make('Basic Details')
69+
->schema([
70+
TextEntry::make('name'),
71+
TextEntry::make('start_date')
72+
->dateTime(),
73+
TextEntry::make('end_date')
74+
->dateTime(),
75+
TextEntry::make('created_at')
76+
->dateTime(),
77+
]),
78+
79+
// Add the comments entry
80+
\Coolsam\NestedComments\Filament\Infolists\CommentsEntry::make('comments'),
81+
]);
82+
}
83+
```
84+
![image](https://github.com/user-attachments/assets/da84b49e-66c7-4453-b5d4-b7b18f204bba)
85+
86+
87+
88+
### Using the Comments Widget inside a Resource Page (e.g EditRecord)
89+
90+
As long as the resource page interacts with the record, the CommentsWidget will resolve the record automatically.
91+
92+
```php
93+
class EditConference extends EditRecord
94+
{
95+
protected static string $resource = ConferenceResource::class;
96+
97+
protected function getHeaderActions(): array
98+
{
99+
return [
100+
Actions\ViewAction::make(),
101+
Actions\DeleteAction::make(),
102+
];
103+
}
104+
105+
protected function getFooterWidgets(): array
106+
{
107+
return [
108+
\Coolsam\NestedComments\Filament\Widgets\CommentsWidget::class,
109+
];
110+
}
111+
}
112+
```
113+
![image](https://github.com/user-attachments/assets/bd56d52d-b791-4f24-a202-b0948574d811)
114+
115+
### Using the Comments Widget in a custom Filament Page (You have to pass $record manually)
116+
117+
```php
118+
// NOTE: It's up to you how to get your record, as long as you pass it to the widget
119+
public function getRecord(): ?Conference
120+
{
121+
return Conference::latest()->first();
122+
}
123+
124+
protected function getFooterWidgets(): array
125+
{
126+
return [
127+
CommentsWidget::make(['record' => $this->getRecord()])
128+
];
129+
}
130+
```
131+
132+
### Using the Comments Page Action in a Resource Page (which interacts with $record)
133+
134+
```php
135+
namespace App\Filament\Resources\ConferenceResource\Pages;
136+
137+
use App\Filament\Resources\ConferenceResource;
138+
use Coolsam\NestedComments\Filament\Actions\CommentsAction;
139+
use Filament\Actions;
140+
use Filament\Resources\Pages\ViewRecord;
141+
use Illuminate\Database\Eloquent\Model;
142+
143+
class ViewConference extends ViewRecord
144+
{
145+
protected static string $resource = ConferenceResource::class;
146+
147+
protected function getHeaderActions(): array
148+
{
149+
return [
150+
CommentsAction::make()
151+
->badgeColor('danger')
152+
->badge(fn(Model $record) => $record->getAttribute('comments_count')),
153+
Actions\EditAction::make(),
154+
];
155+
}
156+
}
157+
```
158+
![image](https://github.com/user-attachments/assets/678d3f1e-b3f9-4a77-b263-af5538c72e2b)
159+
160+
![image](https://github.com/user-attachments/assets/372c6390-ea4e-4d19-8943-784506126cc1)
161+
162+
### Using the Comments Page Action in a custom Filament Page (You have to pass $record manually)
163+
In this case you will have to pass the record attribute manually.
164+
165+
```php
166+
protected function getHeaderActions(): array
167+
{
168+
return [
169+
CommentsAction::make()
170+
->record($this->getRecord()) // Define the logic for getting your record e.g in $this->getRecord()
171+
->badgeColor('danger')
172+
->badge(fn(Model $record) => $record->getAttribute('comments_count')),
173+
Actions\EditAction::make(),
174+
];
175+
}
176+
```
177+
178+
### Using the Comments Table Action
179+
180+
```php
181+
public static function table(Table $table): Table
182+
{
183+
return $table
184+
->columns([
185+
// ... Columns
186+
])
187+
->actions([
188+
\Coolsam\NestedComments\Filament\Tables\Actions\CommentsAction::make()
189+
->button()
190+
->badgeColor('danger')
191+
->badge(fn(Conference $record) => $record->getAttribute('comments_count')),
192+
// ... Other actions
193+
]);
194+
}
195+
```
196+
![image](https://github.com/user-attachments/assets/27eead51-c237-4865-b185-3245629cabe4)
197+
198+
### Using the Comments Blade Component ANYWHERE!
199+
This unlocks incredible possibilities. It allows you to render your comments even in your own frontend blade page. All you have to do is simply pass the commentable `$record` to the blade component
200+
```php
201+
$record = Conference::find(1); // Get your record from the database then,
202+
203+
<x-nested-comments::comments :record="$record"/>
204+
```
205+
206+
Alternatively, you could use the Livewire component if you prefer.
207+
```php
208+
$record = Conference::find(1); // Get your record from the database then,
209+
210+
<livewire:nested-comments::comments :record="$record"/>
211+
```
212+
46213

47214
## Testing
48215

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
],
2222
"require": {
2323
"php": "^8.2",
24-
"awcodes/filament-tiptap-editor": "^3.5",
25-
"filament/filament": "^3",
26-
"kalnoy/nestedset": "^6.0",
24+
"awcodes/filament-tiptap-editor": "^3.5.12",
25+
"filament/filament": "^3.3",
26+
"kalnoy/nestedset": "^6.0.5",
2727
"spatie/laravel-package-tools": "^1.15.0",
28-
"tangodev-it/filament-emoji-picker": "^1.0"
28+
"tangodev-it/filament-emoji-picker": "^1.0.3"
2929
},
3030
"require-dev": {
3131
"barryvdh/laravel-ide-helper": "^3.5",

src/Filament/Infolists/CommentsEntry.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ class CommentsEntry extends Entry
99
{
1010
protected bool | Closure $isLabelHidden = true;
1111

12+
/** @phpstan-ignore-next-line */
1213
protected string $view = 'nested-comments::filament.infolists.comments-entry';
14+
15+
protected array $columnSpan = ['default' => 'full'];
1316
}

src/Filament/Widgets/CommentsWidget.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class CommentsWidget extends Widget
99
{
1010
public ?Model $record = null;
1111

12+
/** @phpstan-ignore-next-line */
1213
protected static string $view = 'nested-comments::filament.widgets.comments-widget';
1314

1415
protected int | string | array $columnSpan = 'full';

0 commit comments

Comments
 (0)