Notable is a Laravel package that adds polymorphic note functionality to any Eloquent model.
Easily attach notes or comments to models with creator tracking, timestamps, and powerful query scopes.
This package is perfect for:
- Internal comments
- Audit logs
- User feedback
- Any kind of trackable textual annotations
β¨ Key Features
- π Polymorphic Relationships β Attach notes to any Eloquent model.
- π€ Creator Tracking β Track who created each note (creator is also polymorphic!).
- β° Timestamps β Automatic
created_at
andupdated_at
tracking. - π Query Scopes β Powerful query methods for filtering and searching notes.
- βοΈ Configurable β Customize table names through the config file.
- π Easy Integration β Simple trait-based implementation.
- π¦ Laravel 10+ Ready β Built for modern Laravel applications.
π Installation
Install via Composer:
composer require eg-mohamed/notable
Publish and run the migrations:
php artisan vendor:publish --tag="notable-migrations"
php artisan migrate
Optionally publish the config file:
php artisan vendor:publish --tag="notable-config"
π― Quick Start
1οΈβ£ Add the Trait to a Model
use MohamedSaid\Notable\Traits\HasNotables;
class SupportTicket extends Model
{
use HasNotables;
}
2οΈβ£ Start Adding Notes
// Customer adds a note
$ticket->addNote('Still experiencing the issue', $customer);
// Support agent responds
$ticket->addNote('Investigating the problem', $agent);
// Get conversation history
$conversation = $ticket->getNotesWithCreator();
π Common Operations
// Retrieve notes
$ticket->getNotes();
$ticket->getNotesToday();
$ticket->getNotesThisWeek();
$ticket->getNotesThisMonth();
$ticket->getNotesInRange('2024-01-01', '2024-12-31');
// Search notes by content
$ticket->searchNotes('error');
// Check if a model has notes
if ($ticket->hasNotes()) {
echo "This ticket has {$ticket->notesCount()} notes.";
}
π Advanced Query Scopes
use MohamedSaid\Notable\Notable;
// Notes by specific creator
$notes = Notable::byCreator($user)->get();
// Notes without creator (system notes)
$systemNotes = Notable::withoutCreator()->get();
// Recent or older notes
$recentNotes = Notable::recent(7)->get();
$oldNotes = Notable::olderThan(30)->get();
// Date-based scopes
$todayNotes = Notable::today()->get();
$monthNotes = Notable::thisMonth()->get();
$rangeNotes = Notable::betweenDates('2024-01-01', '2024-12-31')->get();
// Search text
$searchResults = Notable::search('login')->get();
π Database Schema
Column | Type | Description |
---|---|---|
id |
bigint | Primary key |
note |
text | The note content |
notable_type |
varchar | Polymorphic type (model class) |
notable_id |
bigint | Polymorphic ID (model ID) |
creator_type |
varchar | Creator polymorphic type (nullable) |
creator_id |
bigint | Creator polymorphic ID (nullable) |
created_at |
timestamp | Created timestamp |
updated_at |
timestamp | Updated timestamp |
You can customize the table name in config/notable.php
:
return [
'table_name' => 'notables',
];
π‘ Example Use Cases
User Activity Log
$user->addNote('Password changed', $admin);
$user->addNote('Logged in', $user);
Order Tracking
$order->addNote('Order shipped', $system);
$order->addNote('Delivered successfully', $staff);
Support Tickets
$ticket->addNote('User reported an error', $customer);
$ticket->addNote('Fix deployed', $developer);
π¨βπ» Contributing & Support
- Issues & bug reports: GitHub Issues
- Pull requests are welcome!
- Licensed under the MIT License.
Top comments (0)