2017 © Pedro Peláez
 

library eloquent-meta-relate

Extend Eloquent relationships to support implied polymorphism and merging

image

danhunsaker/eloquent-meta-relate

Extend Eloquent relationships to support implied polymorphism and merging

  • Friday, May 13, 2016
  • by danhunsaker
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Eloquent Meta-Relate

Extend Eloquent relationships to support implied polymorphism and merging, (*1)

Installation

Use composer:, (*2)

composer require danhunsaker/eloquent-meta-relate

Nothing to it!, (*3)

Usage

Include the Danhunsaker\Eloquent\Traits\MetaRelate trait on any model you want to extend:, (*4)

use Danhunsaker\Eloquent\Traits\MetaRelate;
use Illuminate\Database\Eloquent\Model;

class BaseModel extends Model
{
    use MetaRelate;
}

Implied Polymorphic Relationships

Now you can create implied polymorphic relationships simply by providing an array of class names, instead of a single class, wherever multiple models are part of the same relationship:, (*5)

    public function files()
    {
        return $this->hasMany([
            'App\Models\Audio',
            'App\Models\Document',
            'App\Models\Image',
            'App\Models\Video',
        ]);
    }

Relationship Merging

You can also merge existing relationships:, (*6)

    public function forkedTo()
    {
        return $this->hasMany('App\Models\Fork', 'original_id')->with('fork');
    }

    public function forkedFrom()
    {
        return $this->hasMany('App\Models\Fork', 'fork_id')->with('original');
    }

    public function allForks()
    {
        return $this->createMetaRelation()
            ->merge($this->forkedTo())
            ->merge($this->forkedFrom());
    }

Contributions

Contributions (issues, pull requests, etc) are always welcome on GitHub., (*7)

If you find a security issue, please email me directly., (*8)

The Versions

13/05 2016

dev-master

9999999-dev

Extend Eloquent relationships to support implied polymorphism and merging

  Sources   Download

MIT

The Requires

 

by Dan Hunsaker

13/05 2016

v0.1.0

0.1.0.0

Extend Eloquent relationships to support implied polymorphism and merging

  Sources   Download

MIT

The Requires

 

by Dan Hunsaker