PHP code example of graymatter / laravel-audit-chain
1. Go to this page and download the library: Download graymatter/laravel-audit-chain 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/ */
graymatter / laravel-audit-chain example snippets
use GrayMatter\AuditChain\Concerns\HasActivityLog;
use GrayMatter\AuditChain\Contracts\Auditable;
class Post extends Model implements Auditable
{
use HasActivityLog;
}
use GrayMatter\AuditChain\Concerns\HasAuditTrail;
use GrayMatter\AuditChain\Contracts\Auditable;
class Licence extends Model implements Auditable
{
use HasAuditTrail;
}
use GrayMatter\AuditChain\Facades\AuditChain;
AuditChain::batch(function () {
$order->audit('shipped');
$order->update(['status' => 'shipped']);
$inventory->update(['quantity' => $inventory->quantity - 1]);
});
// All 3 audit logs share the same batch_uuid
AuditChain::context(['source' => 'csv_import', 'file' => 'users.csv']);
// All audit logs created after this will
AuditChain::withoutAudit(function () {
// No audit logs created during this callback
User::factory()->count(1000)->create();
});
use GrayMatter\AuditChain\Attributes\PersonalData;
class User extends Model implements Auditable
{
use HasAuditTrail;
#[PersonalData(description: 'User email address')]
public string $email;
#[PersonalData]
public string $name;
}
class User extends Model implements Auditable
{
use HasAuditTrail;
protected array $personalData = ['email', 'name'];
}
class User extends Model implements Auditable
{
use HasAuditTrail;
// Only audit these fields
protected array $auditInclude = ['name', 'email', 'role'];
// Or exclude specific fields
protected array $auditExclude = ['last_login_at'];
}
bash
# Delete logs older than 90 days (default)
php artisan audit:prune
# Custom retention period
php artisan audit:prune --days=365
# Prune only specific model type
php artisan audit:prune --type="App\Models\User"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.