PHPackages                             msafadi/laravel-eloquent-join-with - 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. msafadi/laravel-eloquent-join-with

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

msafadi/laravel-eloquent-join-with
==================================

Laravel Eloquent Join With Relationships

v1.2(5mo ago)1646.0k6[2 issues](https://github.com/msafadi/laravel-eloquent-join-with/issues)MITPHPPHP ^8.3

Since May 19Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/msafadi/laravel-eloquent-join-with)[ Packagist](https://packagist.org/packages/msafadi/laravel-eloquent-join-with)[ RSS](/packages/msafadi-laravel-eloquent-join-with/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (5)Used By (0)

Laravel Eloquent JoinWith
=========================

[](#laravel-eloquent-joinwith)

Laravel Eloquent Join With is a package that simplifies performing efficient database joins on existing Eloquent relationships of type `HasOne` and `BelongsTo`. By utilizing these relationships, JoinWith optimizes performance by executing a single query instead of the two separate queries typically required with the standard `with` method. This translates to faster and more efficient data retrieval.

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

[](#installation)

You can install the package via composer:

```
composer require msafadi/laravel-eloquent-join-with
```

Usage
-----

[](#usage)

There are two ways to use Laravel JoinWith in your application models:

### 1. Use `JoinWith` Trait

[](#1-use-joinwith-trait)

Include the `JoinWith` trait provided by the package in your application models:

```
