Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
/ eloquent-joins Public archive

Support for joins at the relationship level in Laravel's Eloquent ORM.

License

Notifications You must be signed in to change notification settings

tjbp/eloquent-joins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eloquent Joins

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License

This package allows you to simply call $model->join($relation) to join a Laravel Eloquent relationship's table on the keys declared by your relationship. Columns will be selected automatically, and the joined records hydrated as models in the resulting collection. Laravel's Eloquent does support joins normally, but internally calls the underlying query builder, thereby expecting the name of a table and keys to join it on as arguments.

Installation

Eloquent Joins is installable with Composer via Packagist.

Usage

Use trait

Simply use EloquentJoins\ModelTrait in a model:

namespace App;

use EloquentJoins\ModelTrait as EloquentJoinsModelTrait;

class User
{
    use EloquentJoinsModelTrait;

    protected $table = 'users';

    public function orders()
    {
        return $this->hasMany('\App\Order');
    }
}

$users = User::join('orders')->get();

In the above example, $users will contain a collection of all the User models with a corresponding Order model (since we've performed an inner join). Each corresponding Order model can be found in the $orders property on the User model (normally this would contain a collection of models with a matching foreign key).

You can string multiple join() calls, as well as use the other types of join normally available on the underlying query object (joinWhere(), leftJoin(), etc.).

Licence

Eloquent Joins is free and gratis software licensed under the GPL3 licence. This allows you to use Eloquent Joins for commercial purposes, but any derivative works (adaptations to the code) must also be released under the same licence.

About

Support for joins at the relationship level in Laravel's Eloquent ORM.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages