New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jumper423/with-join

Package to convert Eloquent BelongsTo subqueries into one query with left join.
33 1

Larablocks Analysis

jumper423/with-join works with Laravel 5 (latest release 1.1.2, Aug 24, 2016), which reached end of life: no more fixes, even for security.

Laravel 4 in earlier releases.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 5, past end of life
  • No release in the last 12 months (last: Aug 24, 2016)
  • 0 downloads a month (needs 10,000)
  • 1 GitHub star (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Aug 24, 2016.
  • No releases in the last 12 months.
  • First released: Nov 12, 2014.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 3, 2026.

Install
composer require jumper423/with-join
Latest Version:1.1.2
PHP:>=5.4.0
Laravel:5
Older releases:4
License:MIT
Last Updated:Aug 24, 2016
Links: GitHub  ·  Packagist
Maintainer: jumper423

Package to convert Eloquent BelongsTo subqueries into one query with left join

Build Status Latest Stable Version License Code Climate

Usage

Mark relation you want to convert into left join using ->references($relations) method or Model::includes($relations) method:

Model::with('other')->references('other')->orderBy('other.title', 'asc')->get();
 # this will make one sql-query with left join of 'other' relation
 # result object will be the same object
 
Model::includes('first', 'second')->where('first.title', '=', 'my title')->get();
 # will be the same as Model::with('first', 'second')->references('first', 'second')->…

Model extends Eloquent
{
	$includes = ['first', 'second'];
}
Model::where('first.title', '=', 'my title')->get();
# result is same as Model::includes but definition is done within the model
# if you use $with and $includes together it will be merged

Model::with('foreign')->orderBy('field', 'asc')->get();
 # this will work with default behaviour (perform 2 sql-queries)

Example

New Behaviour
StreetImage::includes('street')->first()

will perform the following sql-query:

select 
	`street`.`<…>` as `__f__street---<…>`, 
	`street_images`.* 
from 
	`street_images` 
left join 
	`streets` as `street` on `street`.`id` = `street_images`.`street_id` 
order by `sort` asc 
limit 1
Default Behaviour
StreetImage::with('street')->first()

will perform the following sql-queries:

select `street_images`.* from `street_images` order by `sort` asc limit 1
select `streets`.* from `streets` where `streets`.`id` in (?) order by `title` asc

Object Structure

You will get the same object if you will use includes() method. For example:

StreetImage::includes('street')->first()

will return:

object(StreetImage) {
	<all street image attributes>
	street: object(Street) {
		<all street attributes>
	}
}

Structure will be the same even if you using nested relations:

StreetImage::includes('street.district')->first();

will return:

object(StreetImage) {
	<all street image attributes>
	street: object(Street) {
		<all street attributes>
		district: object(District) {
			<all district attributes>
		}
	}
}

Nested Relations

StreetImage::includes('street.type', 'street.district')->first();

will perform a following sql-query (<…> will be replaced with all table columns):

select 
	 `street`.`<…>` as `__f__street---<…>`,
	 `type`.`<…>` as `__f__street---__f__type---<…>`,
	 `district`.`<…>` as `__f__street---__f__district---<…>`,
	 `street_images`.* 
from 
	`street_images` 
left join 
	`streets` as `street` on `street`.`id` = `street_images`.`street_id` 
left join 
	`street_types` as `type` on `type`.`id` = `street`.`street_type_id` 
left join 
	`districts` as `district` on `district`.`id` = `street`.`district_id` 
order by `sort` asc 
limit 1

instead of performing 4 sql-queries by default Eloquent behaviour:

select `street_images`.* from `street_images` order by `sort` asc limit 1

select `streets`.* from `streets` where `streets`.`id` in (?) order by `title` asc

select * from `street_types` where `street_types`.`id` in (?) order by `title` asc

select * from `districts` where `districts`.`id` in (?) order by `sort` asc

Installation

  1. Require this package in your composer.json and run composer update (or run composer require sleeping-owl/with-join:1.x directly):

     "sleeping-owl/with-join": "1.*"
    
  2. Use \SleepingOwl\WithJoin\WithJoinTrait trait in every eloquent model you want to use this package features:

    class StreetImage extends \Eloquent
    {
    	use \SleepingOwl\WithJoin\WithJoinTrait;
    }
    
  3. That`s all.

Support Library

You can donate via PayPal or in BTC: 13k36pym383rEmsBSLyWfT3TxCQMN2Lekd

Package was written by Sleeping Owl for the Laravel framework and is released under the MIT License. See the LICENSE file for details.

Related Packages

kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

57,980,900 1,567
kitloong/eloquent-power-joins-with-compoships

The Laravel magic applied to joins, with compoships support

19,645 26
llama-laravel/eloquent

Extends Laravel Eloquent ORM.

93 2
reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

1,648,335 212
blasttech/eloquent-related-plus

Adds search and order functionality to Laravel Eloquent related models

29,081 5

Version History

Version Released PHP Laravel License
1.1.2 >=5.4.0 ^5.0 MIT
1.1.1 >=5.4.0 ~5.1.2 MIT
1.1 >=5.4.0 <5.1.2 MIT
1.0.11 >=5.4.0 >=5.0.6 MIT
1.0.10 >=5.4.0 <5.0.6 MIT