PHP code example of motomedialab / simple-laravel-audit

1. Go to this page and download the library: Download motomedialab/simple-laravel-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/ */

    

motomedialab / simple-laravel-audit example snippets


audit('Action performed', ['more_data' => 'Goes here']);

// import the facade
use Motomedialab\SimpleLaravelAudit\Facades\AuditFacade;

// create our audit log
AuditFacade::audit('Action performed', ['more_data' => 'Goes here']);

// import our contract & trait
use Motomedialab\SimpleLaravelAudit\Contracts\IsAuditableEvent;
use Motomedialab\SimpleLaravelAudit\Traits\AuditableEvent;

class MyCustomEvent implements IsAuditableEvent
{
    use AuditableEvent;

    public function handle()
    {
        // ToDo: your event logic.
    }
    
    // optional - by default will be handled by the AuditableEvent trait
    public function getAuditMessage(): string
    {
        return 'Action performed';
    }
    
    // optional - by default will be handled by the AuditableEvent trait
    public function getAuditContext(): array
    {
        return ['more_data' => 'Goes here'];
    }
}

use Illuminate\Database\Eloquent\Model;
use Motomedialab\SimpleLaravelAudit\Traits\AuditableModel;

class YourModel extends Model
{
    use AuditableModel;
    
    /**
    * An array of columns that shouldn't be audited.
    * @var array|string[] 
    */
    protected array $excludedFromAuditing = [
        'created_at',
        'updated_at',
    ];
}

use Motomedialab\SimpleLaravelAudit\Observers\AuditableModelObserver as BaseObserver;

class AuditableObserver extends BaseObserver
{
    // your custom classes here
    // see https://laravel.com/docs/11.x/eloquent#observers for more information
}

php artisan migrate

php artisan vendor:publish --tag=simple-auditor