Getting started
Waypoint Quickstart
In this quickstart you add an audit trail to invoices and show it on the invoice page. It takes about five minutes.
Make the model auditable
Add the Auditable trait and list the attributes you want to log:
php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Waypoint\Auditable;
class Invoice extends Model
{
use Auditable;
protected array $audit = ['number', 'status', 'total', 'due_at'];
}
Change a record
Save the model as usual. Waypoint stores the old and new values together with the logged-in user:
php
$invoice->update(['status' => 'paid']);
$invoice->activities()->first()->changes;
// ['status' => ['old' => 'open', 'new' => 'paid']]
Show the history
Load the activities with their causer and render them in your Blade view:
html
<ul>
@foreach ($invoice->activities()->with('causer')->get() as $activity)
<li>{{ $activity->causer?->name }} {{ $activity->event }} {{ $activity->created_at->diffForHumans() }}</li>
@endforeach
</ul>
Tip
Run
php artisan waypoint:statsto see how many activities each model has written so far.
Next steps
- Log logins and exports with custom events
- Keep the table small by pruning old activities
- Check your audit log in tests
Last updated: