2017 © Pedro Peláez
 

library laravel-eager-relationships

Extend all relationships to optionally include eager loading

image

rdx/laravel-eager-relationships

Extend all relationships to optionally include eager loading

  • Saturday, June 18, 2016
  • by rudiedirkx
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Eager relationship loading

If you want certain relationships to eager load depending relationships, but not always on the same models., (*1)

Different from protected $with

protected $with on a model always loads those relationships when the model is loaded. If you want automatic eager loading sometimes, but not always, this is for you., (*2)

Usage

Add the trait to your model:, (*3)

use rdx\laraveleagerrelationships\HasRelationshipsWith;

class User extends Model {
    use HasRelationshipsWith;
}

And change the model's relationships to use its methods:, (*4)

public function posts() {
    return $this->hasManyWith('categories', Category::class);
}

The differences:, (*5)

  • Add With to the method name: belongsTo becomes belongsToWith etc
  • The first argument must be a valid with() argument:
    • string: 'categories'
    • array: ['categories', 'domains', 'logs']

Which relationships?

All current (Laravel 5.2) relationships:, (*6)

  • hasManyWith
  • belongsToManyWith
  • morphOneWith
  • hasOneWith
  • belongsToWith
  • morphToWith
  • hasManyThroughWith
  • morphManyWith
  • morphToManyWith
  • morphedByManyWith

But I've tested only a few., (*7)

The Versions

18/06 2016

dev-master

9999999-dev

Extend all relationships to optionally include eager loading

  Sources   Download

MIT

The Requires

 

by Rudie Dirkx

18/06 2016

1.0

1.0.0.0

Extend all relationships to optionally include eager loading

  Sources   Download

MIT

The Requires

 

by Rudie Dirkx