centrex/laravel-model-note

This package add note to eloquent model

Maintainers

Package info

github.com/centrex/laravel-model-note

pkg:composer/centrex/laravel-model-note

Statistics

Installs: 2 351

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.