Sarcastic Summary:
The Laravel package Notable is the ultimate solution for adding polymorphic note functionality to your Laravel models. With its powerful polymorphic relationships, creator tracking, timestamps, and query scopes, this package is perfect for internal comments, audit logs, user feedback, and any other kind of trackable textual annotations.
The package comes with a set of key features, including:- Polymorphic Relationships: Attach notes to any Eloquent model, ensuring that notes can belong to multiple models with different types.
- Creator Tracking: Track who created each note, making it easy to keep track of who made changes to each note.
- Timestamps: Automatic created_at
and updated_at
tracking, ensuring that notes are always up-to-date.
– Query Scopes: Powerful query methods for filtering and searching notes, enabling you to retrieve specific notes based on various criteria.
– Configurable: Customize table names through the config file, making it easy to adapt the package to your project’s requirements.
– Easy Integration: A simple trait-based implementation, allowing for easy integration with Laravel 10+ applications.
– Easy to Use: With a straightforward syntax
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.