zairakai / laravel-activity
Enhanced activity logging helpers for Spatie Laravel Activity Log with pivot table support
Package info
gitlab.com/zairakai/php-packages/laravel-activity
pkg:composer/zairakai/laravel-activity
v1.0.0
2026-03-11 19:17 UTC
Requires
- php: ^8.3
- illuminate/contracts: ^11.0 || ^12.0
- illuminate/database: ^11.0 || ^12.0
- illuminate/support: ^11.0 || ^12.0
- spatie/laravel-activitylog: ^4.8
Requires (Dev)
- driftingly/rector-laravel: ^2.1
- ergebnis/composer-normalize: ^2.49
- larastan/larastan: ^3.9
- laravel/pint: ^1.27
- nunomaduro/phpinsights: ^2.13
- orchestra/testbench: ^9.0 || ^10.0
- phpmetrics/phpmetrics: ^2.9
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- rector/rector: ^2.3
- zairakai/laravel-dev-tools: ^1.0
Suggests
- ergebnis/composer-normalize: Automated composer.json normalization
README
Pivot activity logging for Eloquent many-to-many relationships, built on top of Spatie Laravel Activity Log.
Features
- Fluent API — chainable
->activity()->by()->withMessage()->sync()on anyBelongsToManyrelation - Automatic diffing — logs attached, detached, and unchanged IDs on every
syncoperation - Actor tracking —
->by($user)records who performed the action - Custom messages —
->withMessage('Assigned roles')for human-readable log entries - Zero configuration — no config file needed, just
composer require
Requirements
spatie/laravel-activitylogmust be installed and configured
Install
composer require zairakai/laravel-activity
Usage
use App\Models\User;
$user = User::find(1);
// Log a sync operation on a BelongsToMany relationship
$user->roles()
->activity()
->by(auth()->user())
->withMessage('Assigned roles')
->sync([1, 2, 3]);
// Without an actor
$user->permissions()
->activity()
->withMessage('Permissions updated')
->sync([10, 20]);
// Attach and detach also fire activity
$user->tags()->activity()->attach(5);
$user->tags()->activity()->detach(5);
The activity log will record:
attached: IDs that were addeddetached: IDs that were removedunchanged: IDs that were already present
Development
make quality # pint + phpstan + rector + insights + markdownlint + shellcheck
make quality-fast # pint + phpstan + markdownlint
make test # phpunit / pest
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for the project-specific workflow and quality standards.
Getting Help
Made with ❤️ by Zairakai