PHPackages                             cviebrock/eloquent-log-lazy-loading - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. cviebrock/eloquent-log-lazy-loading

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

cviebrock/eloquent-log-lazy-loading
===================================

Log (or disable) Eloquent lazy-loaded relationships.

1.0.0(8y ago)638MITPHPPHP ^7.0

Since Oct 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/cviebrock/eloquent-log-lazy-loading)[ Packagist](https://packagist.org/packages/cviebrock/eloquent-log-lazy-loading)[ Docs](https://github.com/cviebrock/eloquent-log-lazy-loading)[ RSS](/packages/cviebrock-eloquent-log-lazy-loading/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Eloquent Log Lazy Loading
=========================

[](#eloquent-log-lazy-loading)

Warning

This package is abandonned as it hasn't been updated since Laravel 5, and the functionality has been baked into recent versions of Laravel via the [Model::handleLazyLoadingViolationUsing](https://laravel.com/docs/9.x/eloquent-relationships#preventing-lazy-loading) method.

---

Log (or disable) Eloquent lazy-loaded relationships in Laravel 5 to speed up your application.

[![Build Status](https://camo.githubusercontent.com/d4105265c0cff64477fb8b468b5ff534266a145c1b29f0a993dbaea0b2d90f1a/68747470733a2f2f7472617669732d63692e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f672d6c617a792d6c6f6164696e672e7376673f6272616e63683d6d617374657226666f726d61743d666c6174)](https://travis-ci.org/cviebrock/eloquent-log-lazy-loading)[![Latest Stable Version](https://camo.githubusercontent.com/60bc5fae70caa0ce9617d4bed64ccff6380a68fcbbc039d05764c83fc8caf4ba/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f672d6c617a792d6c6f6164696e672f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-log-lazy-loading)[![Latest Unstable Version](https://camo.githubusercontent.com/ad7e1635bbe03feca524360ee8f1ccb7b8d34fad299a640a1316a15fb8578cbc/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f672d6c617a792d6c6f6164696e672f762f756e737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-log-lazy-loading)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ad85a4f3bb08306e07fd45847e24c48327b68fdfa074212e20275ce4ee9f4dea/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6376696562726f636b2f656c6f7175656e742d6c6f672d6c617a792d6c6f6164696e672f6261646765732f7175616c6974792d73636f72652e706e673f666f726d61743d666c6174)](https://scrutinizer-ci.com/g/cviebrock/eloquent-log-lazy-loading)[![Total Downloads](https://camo.githubusercontent.com/d4db58d413f97319c3a9dd2503aa9ab6dd4272c98feb4c8b954194c238d026d9/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f672d6c617a792d6c6f6164696e672f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-log-lazy-loading)[![License](https://camo.githubusercontent.com/ffd916504efc6aab91a1714103c7a3c34bc7668e120370d7f2bba28205366576/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f672d6c617a792d6c6f6164696e672f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-log-lazy-loading)

- [Eloquent Log Lazy Loading](#eloquent-log-lazy-loading)
    - [Why You Might Want This Package](#why-you-might-want-this-package)
    - [Installation](#installation)
    - [Usage](#usage)
    - [Bugs, Suggestions and Contributions](#bugs-suggestions-and-contributions)
    - [Copyright and License](#copyright-and-license)

---

Why You Might Want This Package
-------------------------------

[](#why-you-might-want-this-package)

Eloquent's lazy-loading is great. You can do `Group::find($id)` in your controller, and then loop through `$group->users` in your template without needing to worry about the database queries that run under-the-hood.

The problem comes when you try and loop through `$group->users->addresses`, or some other relation. You may inadvertently be running an SQL query for each iteration of that loop. If you are running a site that gets millions of hits a day, this might not be a good thing!

By logging where your script is lazy-loading relationships, you may be able to optimize your application to avoid unnecessary database calls. At the very least you can see where the bottlenecks are. And, if you want, you can disable lazy-loading entirely and only allow explicitly loaded relations from being accessed.

Installation
------------

[](#installation)

Install the package via composer:

```
$ composer require cviebrock/eloquent-log-lazy-loading
```

That's it!

Usage
-----

[](#usage)

Your models should use the `LogLazyLoading` trait:

```
use Cviebrock\EloquentLogLazyLoading\LogLazyLoading;

class MyModel extends Eloquent
{
    use LogLazyLoading;
}
```

When you attempt to lazy load a relationship, the package will report a `LazyLoadingException` exception and continue normally (i.e. it will load the relationship). This is a great way to check where your application is doing lazy-loading and allows you to refactor, possibly reducing the number of database queries that are called.

However, if you really want to go hard core and halt your application when a relation is lazy-loaded, then just set the `disableLazyLoading` property on your model to `true`. The exception will be thrown, and not just reported.

```
use Cviebrock\EloquentLogLazyLoading\LogLazyLoading;

class MyModel extends Eloquent
{
    use LogLazyLoading;

    protected $disableLazyLoading = true;
}
```

Bugs, Suggestions and Contributions
-----------------------------------

[](#bugs-suggestions-and-contributions)

Thanks to [everyone](https://github.com/cviebrock/eloquent-log-lazy-loading/graphs/contributors)who has contributed to this project.

Please use [Github](https://github.com/cviebrock/eloquent-log-lazy-loading) for reporting bugs, and making comments or suggestions.

See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes.

Copyright and License
---------------------

[](#copyright-and-license)

[eloquent-taggable](https://github.com/cviebrock/eloquent-log-lazy-loading)was written by [Colin Viebrock](http://viebrock.ca) and is released under the [MIT License](LICENSE.md).

Copyright (c) 2017 Colin Viebrock

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3179d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/166810?v=4)[Colin Viebrock](/maintainers/cviebrock)[@cviebrock](https://github.com/cviebrock)

---

Top Contributors

[![cviebrock](https://avatars.githubusercontent.com/u/166810?v=4)](https://github.com/cviebrock "cviebrock (1 commits)")

---

Tags

eloquentlaravellazy-loadingrelationshipslaraveleloquentrelationshiplazy load

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cviebrock-eloquent-log-lazy-loading/health.svg)

```
[![Health](https://phpackages.com/badges/cviebrock-eloquent-log-lazy-loading/health.svg)](https://phpackages.com/packages/cviebrock-eloquent-log-lazy-loading)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11222.5M32](/packages/anourvalar-eloquent-serialize)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

854.1k](/packages/waad-laravel-model-metadata)[mozex/laravel-scout-bulk-actions

Import, flush, and queue-import all your Laravel Scout searchable models at once. Auto-discovers models, runs in bulk, tracks progress.

1437.7k](/packages/mozex-laravel-scout-bulk-actions)[binafy/laravel-reactions

React to something in Laravel framework

875.6k](/packages/binafy-laravel-reactions)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2933.4k9](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
