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:stats to see how many activities each model has written so far.

Next steps

Last updated: