centrex / laravel-model-note
This package add note to eloquent model
v1.3.3
2025-10-09 07:13 UTC
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- larastan/larastan: ^2.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^9.5
- pestphp/pest: ^3.4
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- rector/rector: ^1.2
- spatie/laravel-ray: ^1.26
- dev-main
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.0.2
- v0.0.1
- dev-dependabot/github_actions/dependabot/fetch-metadata-3.1.0
- dev-dependabot/github_actions/ramsey/composer-install-4
- dev-dependabot/github_actions/actions/checkout-6
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-7
This package is auto-updated.
Last update: 2026-04-22 07:08:02 UTC
README
Attach polymorphic notes to any Eloquent model with support for tagging, privacy control, and bulk operations. Notes are stored in a model_notes table and ordered newest-first by default.
Installation
composer require centrex/laravel-model-note
php artisan vendor:publish --tag="laravel-model-note-migrations"
php artisan migrate
Usage
1. Add the trait
use Centrex\LaravelModelNote\HasNotes; class Order extends Model { use HasNotes; }
2. Add notes
$order->addNote('Payment confirmed by finance.'); // Private note (not shown to customers) $order->addPrivateNote('Suspicious address — flag for review.'); // Tagged note $order->addNote('Dispatched via DHL.', tag: 'shipping'); $order->addNote('Customer called in.', isPrivate: true, tag: 'support');
3. Read notes
// Latest note content (shortcut) echo $order->note(); // Latest note object, optionally filtered by tag $note = $order->lastNote('shipping'); echo $note->time_ago; // "2 hours ago" // All notes $order->allNotes(); $order->allNotes('support'); // filtered by tag // Private notes only $order->privateNotes(); $order->privateNotes('shipping');
4. Delete notes
$order->deleteNote(5); $order->deleteNote([5, 6, 7]); $order->deleteNoteByTag('shipping'); $order->deleteAllNotes();
5. Query scopes on ModelNote
use Centrex\LaravelModelNote\ModelNote; ModelNote::private()->get(); ModelNote::public()->get(); ModelNote::withTag('support')->get();
ModelNote attributes
| Attribute | Type | Description |
|---|---|---|
note |
string |
Note content |
tag |
string|null |
Optional category tag |
is_private |
bool |
Hidden from non-admin views |
user_id |
int|null |
Author (defaults to auth()->id()) |
time_ago |
string |
Human-readable age (diffForHumans()) |
Testing
composer test # full suite composer test:unit # pest only composer test:types # phpstan composer lint # pint
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.