{"id":42141870,"url":"https://github.com/kainiklas/laravel-strict-mode","last_synced_at":"2026-01-26T17:21:40.700Z","repository":{"id":61768985,"uuid":"554761657","full_name":"kainiklas/laravel-strict-mode","owner":"kainiklas","description":"Laravel Package to Enable Eloquent \"Strict Mode\" and Further Safety Methods","archived":false,"fork":false,"pushed_at":"2023-10-09T09:52:38.000Z","size":436,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T13:52:22.484Z","etag":null,"topics":["laravel","php"],"latest_commit_sha":null,"homepage":"","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/kainiklas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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-10-20T10:56:11.000Z","updated_at":"2023-04-07T13:14:10.000Z","dependencies_parsed_at":"2023-02-01T02:16:30.784Z","dependency_job_id":null,"html_url":"https://github.com/kainiklas/laravel-strict-mode","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/kainiklas/laravel-strict-mode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kainiklas%2Flaravel-strict-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kainiklas%2Flaravel-strict-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kainiklas%2Flaravel-strict-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kainiklas%2Flaravel-strict-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kainiklas","download_url":"https://codeload.github.com/kainiklas/laravel-strict-mode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kainiklas%2Flaravel-strict-mode/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28782838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: 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":["laravel","php"],"created_at":"2026-01-26T17:21:36.644Z","updated_at":"2026-01-26T17:21:40.422Z","avatar_url":"https://github.com/kainiklas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Package to Enable Eloquent \"Strict Mode\" and Further Safety Methods\n\n![Laravel Strict Mode](art/laravel-strict-mode.png)\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/kainiklas/laravel-strict-mode.svg?style=flat-square)](https://packagist.org/packages/kainiklas/laravel-strict-mode)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/kainiklas/laravel-strict-mode/run-tests.yml?branch=main)](https://github.com/kainiklas/laravel-strict-mode/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/kainiklas/laravel-strict-mode.svg?style=flat-square)](https://packagist.org/packages/kainiklas/laravel-strict-mode)\n\nEnables the following configurable eloquent \"strict mode\" features:\n\n- Prevent Lazy Loading (N+1)\n    - Non-production: Throws an `Illuminate\\Database\\LazyLoadingViolationException` exception\n    - Production: Writes a warning into the logs\n- Prevent defaulting to NULL when using a model's attribute that hasn't been fetched from the DB or doesn't exist on the model\n    - Throws an `Illuminate\\Database\\Eloquent\\MissingAttributeException` exception (all environments)\n    - Alternatively: You can set the config to write a warning to the log\n- Prevent loosing attributes when creating or updating models because of missing attributes in the $fillable array\n    - Throws an `Illuminate\\Database\\Eloquent\\MassAssignmentException` exception (all environments)\n    - Alternatively: You can set the config to write a warning to the log\n\nEnables the following configurable safety methods:\n\n- Long-running command monitoring\n    - Writes a warning into the logs including the command name, user and duration which took longer than the specified threshold (default: 5000ms)\n- Long-running requests monitoring\n    - Writes a warning into the logs including the request url, user and duration which took longer than the specified threshold (default: 5000ms)\n- Long-running single DB query monitoring\n    - Writes an info into the logs including the SQL query and duration which took longer than the specified threshold (default: 1000ms)\n- Long-running DB connection monitoring\n    - Writes an info into the logs including the DB connection name which took longer than the specified threshold (default: 2000ms)\n- Memory Heap Size monitoring\n    - Writes a warning into the logs including when the memory heap size exceeds the specified threshold (default: 50MB)\n\n## Installation\n\n**Laravel Version ^10.0 required.**\n\nYou can install the package via composer:\n\n```bash\ncomposer require kainiklas/laravel-strict-mode\n```\n\nOptionally, you can publish the config file. \n\n```bash\nphp artisan vendor:publish --tag=\"laravel-strict-mode-config\"\n```\n\nYou can influence the behaviour with environment variables.\n\nThis is the contents of the published config file.\n\n```php\nreturn [\n\n    /**\n     * Throws Illuminate\\Database\\LazyLoadingViolationException if model is lazy loaded.\n     * Exception is only thrown if log_lazy_loading is set to false.\n     */\n    'prevent_lazy_loading' =\u003e env(\n        'PREVENT_LAZY_LOADING',\n        true,\n    ),\n\n    /**\n     * Lazy Loading violation is logged. No exception is thrown.\n     * Only works, if prevent_lazy_loading is true.\n     */\n    'log_lazy_loading' =\u003e env(\n        'LOG_LAZY_LOADING',\n        env('APP_ENV') == 'production'\n    ),\n\n    /**\n     * Prevent non-fillable attributes from being silently discarded.\n     * Instead, throws Illuminate\\Database\\Eloquent\\MassAssignmentException.\n     * Exception is only thrown if log_prevent_silently_discarding_attributes is false.\n     */\n    'prevent_silently_discarding_attributes' =\u003e env(\n        'PREVENT_SILENTLY_DISCARDING_ATTRIBUTES',\n        true\n    ),\n\n    /**\n     * Log warning Illuminate\\Database\\Eloquent\\MassAssignmentException\n     * instead of throwing the exception.\n     * Only works if prevent_silently_discarding_attributes is true.\n     */\n    'log_prevent_silently_discarding_attributes' =\u003e env(\n        'LOG_PREVENT_SILENTLY_DISCARDING_ATTRIBUTES',\n        false\n    ),\n\n    /**\n     * If activated an Illuminate\\Database\\Eloquent\\MissingAttributeException\n     * is thrown whenever an attribute is accessed which is not present in the model,\n     * instead of falling back to NULL.\n     *\n     * Exception is only thrown if log_prevent_accessing_missing_attributes is false.\n     */\n    'prevent_accessing_missing_attributes' =\u003e env(\n        'PREVENT_ACCESSING_MISSING_ATTRIBUTES',\n        true\n    ),\n\n    /**\n     * Log warning Illuminate\\Database\\Eloquent\\MissingAttributeException\n     * instead of throwing the exception.\n     * Only works if prevent_accessing_missing_attributes is true.\n     */\n    'log_prevent_accessing_missing_attributes' =\u003e env(\n        'LOG_PREVENT_ACCESSING_MISSING_ATTRIBUTES',\n        false\n    ),\n\n    /**\n     * Logs a warning if a command runs longer than the specified threshold.\n     */\n    'log_long_running_command' =\u003e env(\n        'LOG_LONG_RUNNING_COMMAND',\n        true\n    ),\n\n    /**\n     * Threshold for long running command in milliseconds [ms].\n     */\n    'log_long_running_command_threshold' =\u003e env(\n        'LOG_LONG_RUNNING_COMMAND_THRESHOLD',\n        5000 // [ms]\n    ),\n\n    /**\n     * Logs a warning if a HTTP request runs longer than the specified threshold.\n     */\n    'log_long_running_request' =\u003e env(\n        'LOG_LONG_RUNNING_REQUEST',\n        true\n    ),\n\n    /**\n     * Threshold for long running HTTP request in milliseconds [ms].\n     */\n    'log_long_running_request_threshold' =\u003e env(\n        'LOG_LONG_RUNNING_REQUEST_THRESHOLD',\n        5000 // [ms]\n    ),\n\n    /**\n     * Logs a warning if a DB connection runs longer than the specified threshold.\n     */\n    'log_long_running_total_db_query' =\u003e env(\n        'LOG_LONG_RUNNING_TOTAL_DB_QUERY',\n        true\n    ),\n\n    /**\n     * Threshold for long running db connection in milliseconds [ms].\n     */\n    'log_long_running_total_db_query_threshold' =\u003e env(\n        'LOG_LONG_RUNNING_TOTAL_DB_QUERY_THRESHOLD',\n        2000 // [ms]\n    ),\n\n    /**\n     * Logs a warning if a single DB Query runs longer than the specified threshold.\n     */\n    'log_long_running_single_db_query' =\u003e env(\n        'LOG_LONG_RUNNING_SINGLE_DB_QUERY',\n        true\n    ),\n\n    /**\n     * Threshold for long running single DB Query in milliseconds [ms].\n     */\n    'log_long_running_single_db_query_threshold' =\u003e env(\n        'LOG_LONG_RUNNING_SINGLE_DB_QUERY_THRESHOLD',\n        1000 // [ms]\n    ),\n\n    /**\n     * Logs a warning if a request cycle consumed more memory than the specified threshold.\n     */\n    'log_memory_heap_size' =\u003e env(\n        'LOG_MEMORY_HEAP_SIZE',\n        true\n    ),\n\n    /**\n     * Threshold for memory heap size in Megabytes [MB].\n     */\n    'log_memory_heap_size_threshold' =\u003e env(\n        'LOG_MEMORY_HEAP_SIZE_THRESHOLD',\n        50 // [MB]\n    ),\n\n];\n```\n\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](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Acknowledgements\n\nThis package is based on the following article:\n- [Laravel's safety mechanisms](https://planetscale.com/blog/laravels-safety-mechanisms#model-strictness) by [Aaron Francis](https://github.com/aarondfrancis)\n\n## Credits\n\n- [Kai Niklas](https://github.com/kainiklas)\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%2Fkainiklas%2Flaravel-strict-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkainiklas%2Flaravel-strict-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkainiklas%2Flaravel-strict-mode/lists"}