Package Data | |
---|---|
Maintainer Username: | cgi |
Maintainer Contact: | xuan.0211@gmail.com (XuaNguyen) |
Package Create Date: | 2017-01-25 |
Package Last Update: | 2024-09-10 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-24 03:00:37 |
Package Statistics | |
---|---|
Total Downloads: | 5,927 |
Monthly Downloads: | 34 |
Daily Downloads: | 1 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
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.
Eloquent Joins is installable with Composer via Packagist.
Simply use Llama\Database\Eloquent\ModelTrait in a model:
namespace App;
use Llama\Database\Eloquent\ModelTrait;
class User
{
use ModelTrait;
protected $table = 'users';
public function orders()
{
return $this->hasMany(\App\Order::class);
}
}
$users = \App\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.).
Eloquent Joins is free and gratis software licensed under the [MIT 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.