centrex/laravel-model-note
最新稳定版本:v1.3.3
Composer 安装命令:
composer require centrex/laravel-model-note
包简介
This package add note to eloquent model
README 文档
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.
统计信息
- 总下载量: 2.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-02