2017 © Pedro PelĆ”ez
 

library laravel-owner

Allow Eloquent models to own each other. Supports many to many relationships.

image

inventive/laravel-owner

Allow Eloquent models to own each other. Supports many to many relationships.

  • Friday, February 2, 2018
  • by stephenahiggins
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel Owner, (*1)

Laravel Owner

A simple package that allows Eloquent models to "own" each other, or "be owned" by another model. Supports many to many relationships., (*2)

Examples could include:, (*3)

  1. a user owning a blog post
  2. a user and a team owning multiple files
  3. record being owned by many organisations

Installation

Install using composer:, (*4)

composer require inventive/laravel-owner=dev-master

Add the following to config/app.php:, (*5)

Inventive\LaravelOwner\OwnerServiceProvider::class,

Publish the migrations and config files:, (*6)

php artisan vendor:publish

Run the migrations:, (*7)

php artisan migrate

Add necessary traits your Eloquent models:

If the model can be an owner:, (*8)

use Inventive\LaravelOwner\Traits\Owns;

class User extends Model
{
    use Owns;
}

If the model can be owned by another model:, (*9)

use Inventive\LaravelOwner\Traits\HasOwner;

class Resource extends Model
{
    use HasOwner;
}

Usage

"Owner" model:

Create an ownership:, (*10)

$user->own($model);

Remove an ownership:, (*11)

$user->disown($model);

Return a collection of all the models owned by the parent model:, (*12)

$user->owns();

Does the user own this model?, (*13)

$user->ownsModel($model);

Which models of this type does the parent model own? This method either takes a child model, or a name-spaced class name., (*14)

$user->ownsModelType($model); // Use a model
$user->ownsModelType(ā€˜App\Resource’); // Use class name

"Owned" model:

Return a collection of all the model's owners:, (*15)

$model->owners();

Is the model is owned by another model?, (*16)

$model->isOwnedBy($owner);

Add an owner to the model:, (*17)

$model->addOwner($owner);

Remove an owner from the model, (*18)

$model->removeOwner($owner);

License

MIT, (*19)

The Versions

02/02 2018

dev-master

9999999-dev

Allow Eloquent models to own each other. Supports many to many relationships.

  Sources   Download

MIT

The Requires

 

by Avatar stephen