PHP code example of aedart / athenaeum-audit

1. Go to this page and download the library: Download aedart/athenaeum-audit 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/ */

    

aedart / athenaeum-audit example snippets


namespace Acme\Models;

use Illuminate\Database\Eloquent\Model;
use Aedart\Audit\Traits\RecordsChanges;

class Category extends Model
{
    use RecordsChanges;
}

$category = Category::create( [ 'name' => 'My category' ]);

// Obtain the "changes" made (in this case a "create" event) 
$changes = $category->recordedChanges()->first();

print_r($changes->toArray());

// Example output:
//    [
//      "id" => 1
//      "user_id" => null
//      "auditable_type" => "Acme\Models\Category"
//      "auditable_id" => "24"
//      "type" => "created"
//      "message" => "Recording created event"
//      "original_data" => null
//      "changed_data" => [
//        "name" => "My Category"
//        "id" => 1
//      ]
//      "performed_at" => "2021-04-28T11:07:24.000000Z"
//      "created_at" => "2021-04-28T11:07:24.000000Z"
//    ]