PHP code example of hypathbel / model-scribe

1. Go to this page and download the library: Download hypathbel/model-scribe 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/ */

    

hypathbel / model-scribe example snippets


'drivers' => [
    'database' => [
        'driver'     => 'database',
        'table'      => 'model_scribe_logs', // Default table
        'stores' => [
            'invoices' => [
                'table'      => 'invoice_logs',
                'connection' => 'audit_db', // Optional: use a different connection
            ],
            'orders' => [
                'table' => 'order_logs',
            ],
        ],
        'retention' => [
            'type' => 'days',
            'days' => 90,
        ],
    ],
],

use HypathBel\ModelScribe\Traits\HasAuditLog;

class Product extends Model
{
    use HasAuditLog;
}

class Order extends Model
{
    use HasAuditLog;

    // Only log specific events
    protected array $auditEvents = ['created', 'updated'];

    // Limit which attributes are recorded per event
    protected array $auditAttributes = [
        'updated' => ['status', 'total_price', 'shipping_address'],
    ];

    // Route to a specific store/table
    protected string $auditLogName = 'orders';

    // Add searchable tags to every log entry
    protected array $auditTags = ['warehouse-A', 'priority-high'];
}

use HypathBel\ModelScribe\Facades\ModelScribe;
use HypathBel\ModelScribe\Enums\ScribeEvent;

ModelScribe::log(
    event: ScribeEvent::Custom,
    logName: 'system',
    description: 'User initiated a bulk export',
    properties: ['format' => 'csv', 'rows' => 1200],
    tags: ['export']
);
bash
php artisan vendor:publish --tag="model-scribe-config"
php artisan vendor:publish --tag="model-scribe-migrations"
bash
php artisan migrate