1. Go to this page and download the library: Download eg-mohamed/notable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
eg-mohamed / notable example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use MohamedSaid\Notable\Traits\HasNotables;
class User extends Model
{
use HasNotables;
}
$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";
}
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);
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');
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();
// 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->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