PHP code example of temistocle1998 / laravel-model-tracker
1. Go to this page and download the library: Download temistocle1998/laravel-model-tracker 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/ */
temistocle1998 / laravel-model-tracker example snippets
use Tracker\Traits\TracksChanges;
class Product extends Model
{
use TracksChanges;
}
return [
'enabled' => true, // Enable or disable the tracking
'exclude_fields' => ['password', 'remember_token'], // Fields you don't want to track
];
use Tracker\Models\ModelChange;
// Get all changes for a specific model
$changes = ModelChange::where('model_type', 'App\Models\Product')
->where('model_id', $productId)
->get();
// Display the changes
foreach ($changes as $change) {
echo $change->changes;
}
@foreach ($product->changes as $change)
<p>Field: {{ $change['field'] }} | Old Value: {{ $change['old_value'] }} | New Value: {{ $change['new_value'] }}</p>
@endforeach