Get up and running with the Activity Logger package in 5 minutes.
composer require gottvergessen/activity
php artisan activity:install
php artisan migrateAdd the TracksModelActivity trait to any model you want to track:
use Gottvergessen\Activity\Traits\TracksModelActivity;
class User extends Model
{
use TracksModelActivity;
}Done! All changes to the User model are now logged automatically.
Add InteractsWithActivity to access activity relationships:
use Gottvergessen\Activity\Traits\InteractsWithActivity;
class User extends Model
{
use TracksModelActivity, InteractsWithActivity;
}
// View activities
$user->activities()->get(); // All activities
$user->latestActivity(); // Most recent
$user->recentActivities(10); // Last 10class User extends Model
{
use TracksModelActivity;
protected array $ignoredAttributes = ['password'];
}class Invoice extends Model
{
use TracksModelActivity;
public function activityDescription(string $event): string
{
return "Invoice #{$this->id} was {$event}";
}
}use Gottvergessen\Activity\Models\Activity;
Activity::forEvent('updated')->get();
Activity::forSubject($user)->get();
Activity::causedBy($admin)->get();
Activity::betweenDates($start, $end)->get();use Gottvergessen\Activity\Activity;
Activity::batch(function () {
$user->update(['name' => 'Jane']);
$user->profile()->update(['bio' => 'New bio']);
// Both logged with same batch_id
});use Gottvergessen\Activity\Support\ActivityContext;
ActivityContext::withoutLogging(function () {
User::create(['name' => 'Test']); // Not logged
});php artisan activity:prune --days=90Edit config/activity.php to customize:
return [
'enabled' => true, // Global on/off
'capture_causer' => true, // Log authenticated user
'ignore_attributes' => [ // Fields to always ignore
'created_at',
'updated_at',
'password',
],
];- Read the full documentation
- Check out detailed examples
- Explore query scopes
- Schedule log pruning
- Review EXAMPLES.md for real-world patterns
- Check the database schema
- See all available scopes