{"id":36992924,"url":"https://github.com/elaborate-code/laravel-eloquent-logs","last_synced_at":"2026-01-13T23:45:05.536Z","repository":{"id":49095045,"uuid":"517157137","full_name":"elaborate-code/laravel-eloquent-logs","owner":"elaborate-code","description":"[Abandoned] Log changes that occur on Eloquent models","archived":true,"fork":false,"pushed_at":"2023-10-09T19:41:10.000Z","size":98,"stargazers_count":19,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-10T09:16:29.345Z","etag":null,"topics":["eloquent","events","laravel","logging","package"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/elaborate-code/laravel-eloquent-logs","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elaborate-code.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-23T20:23:45.000Z","updated_at":"2023-11-10T17:19:47.000Z","dependencies_parsed_at":"2023-02-01T04:01:01.031Z","dependency_job_id":null,"html_url":"https://github.com/elaborate-code/laravel-eloquent-logs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/elaborate-code/laravel-eloquent-logs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elaborate-code%2Flaravel-eloquent-logs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elaborate-code%2Flaravel-eloquent-logs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elaborate-code%2Flaravel-eloquent-logs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elaborate-code%2Flaravel-eloquent-logs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elaborate-code","download_url":"https://codeload.github.com/elaborate-code/laravel-eloquent-logs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elaborate-code%2Flaravel-eloquent-logs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","events","laravel","logging","package"],"created_at":"2026-01-13T23:45:05.484Z","updated_at":"2026-01-13T23:45:05.531Z","avatar_url":"https://github.com/elaborate-code.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-eloquent-logs\n\n[![Packagist Version](https://img.shields.io/packagist/v/elaborate-code/laravel-eloquent-logs?style=for-the-badge)](https://packagist.org/packages/elaborate-code/laravel-eloquent-logs)\n[![Packagist Downloads (custom server)](https://img.shields.io/packagist/dt/elaborate-code/laravel-eloquent-logs?style=for-the-badge)](https://packagist.org/packages/elaborate-code/laravel-eloquent-logs)\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/elaborate-code/laravel-eloquent-logs/run-tests?label=Tests\u0026style=for-the-badge)](https://github.com/elaborate-code/laravel-eloquent-logs/actions/workflows/run-tests.yml)\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/elaborate-code/laravel-eloquent-logs/Fix%20PHP%20code%20style%20issues?label=Code%20Style\u0026style=for-the-badge)](https://github.com/elaborate-code/laravel-eloquent-logs/actions/workflows/fix-php-code-style-issues.yml)\n![maintained](https://img.shields.io/maintenance/yes/2022)\n![Production ready](https://img.shields.io/badge/Production%20ready-no-red)\n\n![banner](https://banners.beyondco.de/Eloquent%20logs.png?theme=dark\u0026packageManager=composer+require\u0026packageName=elaborate-code%2Flaravel-eloquent-logs\u0026pattern=circuitBoard\u0026style=style_1\u0026description=A+simple+way+to+log+changes+that+occur+on+Eloquent+models\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg)\n\nLog what happens to your Eloquent models (`created`|`updated`|`deleted`|`soft deleted`|`restored`|`force deleted`) and keep and eye on **who** made the change, **how** and **when**. \n\nThis solution is simple to integrate and introduces minimal changes to your project: 1 migration, 1 model, 1 trait, and 1 facade.\n\n## Installation\n\nInstall the package via composer:\n\n```bash\ncomposer require elaborate-code/laravel-eloquent-logs\n```\n\nPublish the migrations:\n\n```bash\nphp artisan vendor:publish --tag=\"eloquent-logs-migrations\"\n```\n\nRun the migrations:\n\n```bash\nphp artisan migrate\n```\n\n### Publishing config file [Optional]\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"eloquent-logs-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n    'logs_model' =\u003e \\ElaborateCode\\EloquentLogs\\Models\\EloquentLog::class,\n    'logs_table' =\u003e 'eloquent_logs',\n\n    'user' =\u003e \\App\\Models\\User::class,\n];\n```\n\nThat allows you to rename the `logs_table` before running the migrations.\n\n## Usage\n\nPick an **Eloquent model** that you want to log the changes that happen to it and add the `HasLogs` trait to it.\n\n```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass ExampleModel extends Model\n{\n    use \\ElaborateCode\\EloquentLogs\\Concerns\\HasLogs;\n    // ...\n}\n```\n\nAfter adding that trait, every change made to the model will be recorded.\n\nImportant warning from [Laravel docs](https://laravel.com/docs/9.x/eloquent#events:~:text=When%20issuing%20a%20mass%20update%20or,when%20performing%20mass%20updates%20or%20deletes.)\n\n\u003e When issuing a **mass update or delete** query via Eloquent, the `saved`, `updated`, `deleting`, and `deleted` model events will not be dispatched for the affected models. This is because the models are never actually retrieved when performing mass updates or deletes.\n\n### Retrieving logs\n\nYou can load a model's logs using the `eloquentLogs` relationship:\n\n```php\n$example_model-\u003eeloquentLogs;\n\n$example_model-\u003eload('eloquentLogs');\n\nApp\\Models\\ExampleModel::with('eloquentLogs')-\u003efind($id);\n```\n\nAnd you can query logs directly:\n\n```php\n// latest 5 logs with affected models\nElaborateCode\\EloquentLogs\\Models\\EloquentLog::with('loggable')-\u003elatest()-\u003elimit(5)-\u003eget()\n```\n\n### Grouping queries\n\nBy default each one model event will result in a query to log the action.\n\n```php\n$example_model = ExampleModel::create(['name' =\u003e 'foo']);\n\n$example_model-\u003eupdate(['name' =\u003e 'bar']);\n\n$example_model-\u003edelete();\n\n// ⚠️ This will result in 3 queries to insert the 3 events logs into the database  \n```\n\nYou can improve the logging process by using the `CacheEloquentLogQueries` facade\n\n```php\nuse ElaborateCode\\EloquentLogs\\Facades\\CacheEloquentLogQueries;\n\nCacheEloquentLogQueries::start();\n\n$example_model = ExampleModel::create(['name' =\u003e 'foo']);\n\n$example_model-\u003eupdate(['name' =\u003e 'bar']);\n\n$example_model-\u003edelete();\n\nCacheEloquentLogQueries::execute();\n\n// 👍 This will result in 1 query to insert the 3 events logs into the database  \n```\n\nThe facade includes other methods that you wouldn't necessarily need to use:\n\n```php\n// Stops caching and empties the cache without queries execution\nCacheEloquentLogQueries::reset();\n\n// Empties the cache but doesn't stop caching\nCacheEloquentLogQueries::flushQueries();\n\n// Stops caching until the reuse of start() and doesn't empty the cache\nCacheEloquentLogQueries::suspend();\n\n// Returns a boolean\nCacheEloquentLogQueries::isCaching();\n```\n\n### Ignoring events\n\nYou can specify the events to not log on the model instances by listing the events to ignore on `YourModel::$loggableOptions['ignore']`.\n\n```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass ExampleModel extends Model\n{\n    use \\ElaborateCode\\EloquentLogs\\Concerns\\HasLogs;\n\n    public static array $loggableOptions = [\n        'ignore' =\u003e ['created', 'updated', 'deleted', 'softDeleted', 'forceDeleted', 'restored'],\n    ];\n    // ...\n}\n```\n\n### Muting Eloquent events [Laravel stuff]\n\nFrom seeders:\n\n```php\nnamespace Database\\Seeders;\n\nuse Illuminate\\Database\\Console\\Seeds\\WithoutModelEvents;\nuse Illuminate\\Database\\Seeder;\n\nclass DatabaseSeeder extends Seeder\n{\n    use WithoutModelEvents; // Add this trait\n\n    public function run(): void\n    {\n        // Silent eloquent queries ...\n    }\n}\n```\n\nAnywhere from your code:\n\n```php\n\\Illuminate\\Database\\Eloquent\\Model::unsetEventDispatcher();\n\n// Silent eloquent queries ...\n\n\\Illuminate\\Database\\Eloquent\\Model::setEventDispatcher(app(Dispatcher::class));\n// ...\n```\n\nExplore the [Eloquent docs](https://laravel.com/docs/9.x/eloquent#muting-events) for more options\n\n## Alternative\n\nAmong the bajillion packages that Spatie has so graciously bestowed upon the community, you'll find the excellent [laravel-Alternative](https://github.com/spatie/laravel-activitylog) package.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/elaborate-code/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [medilies](https://github.com/elaborate-code)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felaborate-code%2Flaravel-eloquent-logs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felaborate-code%2Flaravel-eloquent-logs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felaborate-code%2Flaravel-eloquent-logs/lists"}