PHP code example of softartisan / laravel-model-audits

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

    

softartisan / laravel-model-audits example snippets


use Illuminate\Database\Eloquent\Model;
use SoftArtisan\LaravelModelAudits\Concerns\IsAuditable;

class Post extends Model
{
    use IsAuditable;

    protected $fillable = ['title', 'content', 'secret_token'];
}

$post = Post::find(1);
$audits = $post->audits()->latest('audit_id')->get();

class Post extends Model
{
    use IsAuditable;

    protected array $hidden_for_audit = ['secret_token'];
}

$audit = $post->audits()->latest('audit_id')->first();
$audit->restore();

// config/model-audits.php
'pruning' => [
    'enabled' => true,
    'keep_for_days' => 90,
],

protected function schedule(Schedule $schedule): void
{
    $schedule->command('model:prune')->daily();
}

use SoftArtisan\LaravelModelAudits\Integrations\Mcp\ModelAuditsServer;
use Illuminate\Support\Facades\Mcp;

// Web transport (HTTP)
Mcp::server('model-audits', ModelAuditsServer::class);

// Local transport (STDIO)
Mcp::local('model-audits', ModelAuditsServer::class);
bash
php artisan vendor:publish --tag="laravel-model-audits-config"
bash
php artisan vendor:publish --tag="laravel-model-audits-migrations"
php artisan migrate