Search by

karim-tao / laravel-violation-logger

Logs Laravel and Eloquent strict mode violations to a JSON file, grouped by the line that caused them, instead of throwing. Turn strict mode on, run your app, fix the list.

Maintainers

Package info

github.com/karim-tao/laravel-violation-logger

pkg:composer/karim-tao/laravel-violation-logger

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

0.2.0 2026-09-07 15:26 UTC

This package is auto-updated.

Last update: 2026-09-07 15:27:55 UTC


README

Tests Latest Stable Version License

Logs Eloquent strict mode violations to a JSON file instead of throwing, with the line that caused them and how many times:

{
    "app/Http/Controllers/PostController.php:24": {
        "App\\Models\\Post": {
            "lazy": { "author": 30 },
            "missing": { "body": 1 }
        }
    }
}

Run your test suite, fix the list.

Installation

Requires PHP 8.3+ and Laravel 12 or 13.

You can install the package via composer:

composer require karim-tao/laravel-violation-logger --dev

That's it — the ViolationLoggerServiceProvider is auto-discovered, so you're ready to go.

Usage

Turn strict mode on:

// app/Providers/AppServiceProvider.php

Model::shouldBeStrict(! $this->app->isProduction());

Violations now go to storage/logs/violations.json instead of throwing.

Type Switch What it means
lazy Model::preventLazyLoading() a relation was loaded outside of eager loading (N+1)
missing Model::preventAccessingMissingAttributes() an attribute was read that the query did not select
discarded Model::preventSilentlyDiscardingAttributes() a mass assigned attribute was dropped because it is not fillable

How it works

  • The provider registers Laravel's own handleLazyLoadingViolationUsing, handleMissingAttributeViolationUsing and handleDiscardedAttributeViolationUsing callbacks, so nothing runs unless strict mode is on.
  • The call site is the first frame of the backtrace outside vendor/ and outside any other Composer dependency, so it always points at your code.
  • Every violation is written straight away, under an exclusive lock, so requests, queued jobs and test workers can share the file.
  • Counts add up until you delete the file.

Testing

composer test

License

Laravel Violation Logger is open-sourced software licensed under the MIT license.