The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Notable

Notable stats

Downloads
6
Stars
0
Open Issues
0
Forks
0

View on GitHub →

This is my package notable

πŸ“ Notable - Laravel Notes Package

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 mohamedsaid/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 photo

I love self-education 😊 Full-Stack PHP Web Developer ❀ Laravel Fan & Lover πŸ™Œβ€ Filament

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Eg Mohamed Notable Related Articles

Building a Laravel Translation Package – Handling Missing Translation Keys image

Building a Laravel Translation Package – Handling Missing Translation Keys

Read article
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360Β° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit