eg-mohamed/notable
Composer 安装命令:
composer require eg-mohamed/notable
包简介
This is my package notable
README 文档
README
Notable is a powerful Laravel package that enables you to add notes to any Eloquent model through polymorphic relationships. Perfect for adding internal comments, audit logs, user feedback, or any textual annotations to your models.
✨ Features
- 🔗 Polymorphic Relationships - Attach notes to any Eloquent model
- 👤 Creator Tracking - Track who created each note (also polymorphic!)
- ⏰ Timestamps - Automatic created_at and updated_at tracking
- 🔍 Query Scopes - Powerful query methods for filtering notes
- 🎯 Configurable - Customize table names through config
- 🚀 Easy Integration - Simple trait-based implementation
- 📦 Laravel 10+ Ready - Built for modern Laravel applications
🚀 Installation
Install the package 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 Your Model
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use MohamedSaid\Notable\Traits\HasNotables; class User extends Model { use HasNotables; }
2. Start Adding Notes
$user = User::find(1); // Simple note $user->addNote('User completed onboarding process'); // Note with creator $admin = User::find(2); $user->addNote('Account verified by admin', $admin); // Get all notes $notes = $user->getNotes(); // Check if model has notes if ($user->hasNotes()) { echo "This user has {$user->notesCount()} notes"; }
📚 Complete Usage Guide
Adding Notes
// Basic note $model->addNote('Something noteworthy happened'); // Note with creator (any model) $model->addNote('Action performed', $currentUser); $model->addNote('System generated note', $systemBot);
Retrieving Notes
// Get all notes (newest first) $notes = $model->getNotes(); // Get notes with creator information $notesWithCreators = $model->getNotesWithCreator(); // Get latest note $latestNote = $model->getLatestNote(); // Get notes by specific creator $adminNotes = $model->getNotesByCreator($admin); // Check if model has notes $hasNotes = $model->hasNotes(); // Count notes $count = $model->notesCount(); // Enhanced retrieval methods $todayNotes = $model->getNotesToday(); $weekNotes = $model->getNotesThisWeek(); $monthNotes = $model->getNotesThisMonth(); $rangeNotes = $model->getNotesInRange('2024-01-01', '2024-12-31'); $searchResults = $model->searchNotes('error');
Managing Notes
// Update a note $model->updateNote($noteId, 'Updated note content'); // Delete a note $model->deleteNote($noteId);
Query Scopes
The Notable model includes powerful 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 notes (last 7 days by default) $recentNotes = Notable::recent()->get(); $lastMonth = Notable::recent(30)->get(); // Older notes (30+ days by default) $oldNotes = Notable::olderThan(30)->get(); // Date-based scopes $todayNotes = Notable::today()->get(); $weekNotes = Notable::thisWeek()->get(); $monthNotes = Notable::thisMonth()->get(); $yearNotes = Notable::thisYear()->get(); // Date range filtering $rangeNotes = Notable::betweenDates('2024-01-01', '2024-12-31')->get(); // Search note content $searchResults = Notable::search('error')->get(); $containingText = Notable::containingText('login')->get(); // Combine scopes $recentAdminNotes = Notable::byCreator($admin) ->thisMonth() ->search('important') ->orderBy('created_at', 'desc') ->get();
🗂️ Database Schema
The package creates a notables table with the following structure:
| 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 | When the note was created |
updated_at |
timestamp | When the note was last updated |
⚙️ Configuration
Publish the config file to customize the package:
php artisan vendor:publish --tag="notable-config"
<?php // config/notable.php return [ // Customize the table name 'table_name' => 'notables', ];
🎨 Advanced Examples
User Activity Log
class User extends Model { use HasNotables; public function logActivity(string $activity, ?Model $performer = null) { return $this->addNote("User activity: {$activity}", $performer); } } // Usage $user->logActivity('Logged in', $user); $user->logActivity('Password changed', $user); $user->logActivity('Account suspended', $admin);
Order Tracking
class Order extends Model { use HasNotables; public function addStatusNote(string $status, ?User $updatedBy = null) { return $this->addNote("Order status changed to: {$status}", $updatedBy); } } // Usage $order->addStatusNote('Processing', $staff); $order->addStatusNote('Shipped', $system); $order->addStatusNote('Delivered');
Support Tickets
class SupportTicket extends Model { use HasNotables; } // Customer adds note $ticket->addNote('Still experiencing the issue', $customer); // Support agent responds $ticket->addNote('Investigating the problem', $agent); // Get conversation history $conversation = $ticket->getNotesWithCreator();
🔍 Model Relationships
Access notes directly through Eloquent relationships:
// Get the polymorphic relationship $model->notables(); // Returns MorphMany relationship // With eager loading $users = User::with('notables.creator')->get(); // Load notes later $user->load('notables');
📝 Note Model Properties
Each note instance provides:
$note = $model->getLatestNote(); $note->note; // The note content $note->notable; // The parent model $note->creator; // The creator model (nullable) $note->created_at; // When it was created $note->updated_at; // When it was updated
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
🐛 Bug Reports
If you discover any bugs, please create an issue on GitHub.
📄 License
The MIT License (MIT). Please see License File for more information.
👨💻 Credits
Made with ❤️ by Mohamed Said
eg-mohamed/notable 适用场景与选型建议
eg-mohamed/notable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.24k 次下载、GitHub Stars 达 77, 最近一次更新时间为 2025 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「notable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eg-mohamed/notable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eg-mohamed/notable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eg-mohamed/notable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 7.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 77
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-20