1. Go to this page and download the library: Download coolsam/nested-comments library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
coolsam / nested-comments example snippets
use Coolsam\NestedComments\Traits\HasComments;
class Conference extends Model
{
use HasComments;
// ...
}
use Coolsam\NestedComments\Traits\HasReactions;
class Conference extends Model
{
use HasReactions;
// ...
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make('Basic Details')
->schema([
TextEntry::make('name'),
TextEntry::make('start_date')
->dateTime(),
TextEntry::make('end_date')
->dateTime(),
TextEntry::make('created_at')
->dateTime(),
]),
// Add the comments entry
\Coolsam\NestedComments\Filament\Infolists\CommentsEntry::make('comments'),
]);
}
// NOTE: It's up to you how to get your record, as long as you pass it to the widget
public function getRecord(): ?Conference
{
return Conference::latest()->first();
}
protected function getFooterWidgets(): array
{
return [
CommentsWidget::make(['record' => $this->getRecord()])
];
}
namespace App\Filament\Resources\ConferenceResource\Pages;
use App\Filament\Resources\ConferenceResource;
use Coolsam\NestedComments\Filament\Actions\CommentsAction;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Database\Eloquent\Model;
class ViewConference extends ViewRecord
{
protected static string $resource = ConferenceResource::class;
protected function getHeaderActions(): array
{
return [
CommentsAction::make()
->badgeColor('danger')
->badge(fn(Model $record) => $record->getAttribute('comments_count')),
Actions\EditAction::make(),
];
}
}
protected function getHeaderActions(): array
{
return [
CommentsAction::make()
->record($this->getRecord()) // Define the logic for getting your record e.g in $this->getRecord()
->badgeColor('danger')
->badge(fn(Model $record) => $record->getAttribute('comments_count')),
Actions\EditAction::make(),
];
}
public static function table(Table $table): Table
{
return $table
->columns([
// ... Columns
])
->actions([
\Coolsam\NestedComments\Filament\Tables\Actions\CommentsAction::make()
->button()
->badgeColor('danger')
->badge(fn(Conference $record) => $record->getAttribute('comments_count')),
// ... Other actions
]);
}
$record = Conference::find(1); // Get your record from the database then,
<x-nested-comments::comments :record="$record"/>
$record = Conference::find(1); // Get your record from the database then,
<livewire:nested-comments::comments :record="$record"/>
use Coolsam\NestedComments\Traits\HasReactions;
class Conference extends Model
{
use HasReactions;
// ...
}
$conference = Conference::find(1);
$comference->react('👍'); // React to the conference with a thumbs up emoji
$conference = Conference::find(1);
$reactions = $conference->reactions; // Get the reactions for the conference
/**
* @var \Illuminate\Database\Eloquent\Model&\Coolsam\NestedComments\Concerns\HasReactions $conference
*/
$conference = Conference::find(1);
$conference->total_reactions; // Get the total number of reactions for the conference
$conference->reactions_counts; // Get the no of reactions for each emoji for the model
$conference->my_reactions; // Get the reactions for the current user
$conference->emoji_reactors // Get the list of users who reacted to the model, grouped by emoji
$conference->isAllowed('👍') // check if the app allows the user to react with the specified emoji
$conference->reactions_map // return the map of all the reactions for the model, grouped by emoji. This tells you the number of reactions for each emoji, and whether the current user has reacted with that emoji
use Coolsam\NestedComments\Filament\Infolists\ReactionsEntry;
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make('Basic Details')
->schema([
TextEntry::make('name'),
TextEntry::make('start_date')
->dateTime(),
TextEntry::make('end_date')
->dateTime(),
TextEntry::make('created_at')
->dateTime(),
// Add the reactions entry
ReactionsEntry::make('reactions')->columnSpanFull(),
])->columns(4),
]);
}
$record = Conference::find(1); // Get your record from the database then,
$record = Conference::find(1); // Get your record from the database then,
bash
php artisan nested-comments:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.