Overview
The LogAction is a FilamentPHP action designed for logging internal messages or notes related to a specific record within AureusERP. It allows users to add detailed logs with subjects, rich-text descriptions, and file attachments while ensuring that internal messages remain properly categorized and attributed to the correct user.
Features
- Supports adding a subject line optionally.
- Utilizes a rich text editor for detailed message descriptions.
- Allows file attachments with multiple file formats.
- Associates logs with the authenticated user.
- Provides real-time visibility toggling for the subject field.
- Displays success and error notifications.
- Uses a modal for user input.
Action Registration
The LogAction is a FilamentPHP action that should be registered within your Filament resource or component. Its default name is log.action.
php
use Webkul\Chatter\Filament\Actions\Chatter\LogAction;
LogAction::make()
->label('Log Message')
->modalHeading('Add Log Entry')
->icon('heroicon-o-chat-bubble-oval-left');Form Schema
The form consists of:
- Subject (optional): Can be toggled using the
add_subjectaction. - Rich Text Editor: Captures the detailed log message.
- File Attachments: Allows uploading images, PDFs, Word documents, Excel sheets, and plain text files.
- Hidden Field: Ensures the type is set to
note.
Toggle Subject Field
A button labeled Add Subject or Hide Subject controls the visibility of the subject input field dynamically.
Rich Text Editor
- Enables detailed descriptions with text formatting.
- Supports
@user mentions through the chatter mention provider. - Supports file attachments within the editor (stored in the
log-attachmentsdirectory).
File Upload
- Supports multiple file types: images, PDFs, Word, Excel, and text files.
- Uploads files to the
log-attachmentsdirectory on thepublicdisk. - Limits each file to 10 MB.
- Displays preview for uploaded files.
Action Execution
When executed, LogAction:
- Retrieves the authenticated user and attaches the log entry to the respective record.
- Saves the message as an internal note (
is_internal = true). - Attaches uploaded files to the log message.
- Displays success or error notifications based on the operation result.
- Dispatches a
chatter.refreshLivewire event so the chatter panel reloads.
php
use Exception;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
->action(function (array $data, ?Model $record = null) {
try {
$user = Filament::auth()->user() ?? Auth::user();
$data['name'] = $record->name;
$data['causer_type'] = $user->getMorphClass();
$data['causer_id'] = $user->id;
$data['is_internal'] = true;
$message = $record->addMessage($data, $user->id);
if (! empty($data['attachments'])) {
$record->addAttachments($data['attachments'], ['message_id' => $message->id]);
}
Notification::make()
->success()
->title('Log entry added successfully')
->send();
} catch (Exception $e) {
report($e);
Notification::make()
->danger()
->title('Failed to add log entry')
->send();
}
})