faustbrian/laravel-collectable

This package is abandoned and no longer maintained. The author suggests using the artisanry/collectable package instead.

Collectable Polymorphic Eloquent Models for Laravel 5

4.2.0 2019-08-28 13:01 UTC

This package is auto-updated.

Last update: 2019-08-28 13:25:24 UTC


README

Build Status PHP from Packagist Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/collectable

To get started, you'll need to publish the vendor assets and migrate:

php artisan vendor:publish --provider="Artisanry\Collectable\CollectableServiceProvider" && php artisan migrate

Usage

Setup a Model
<?php

namespace App;

use Artisanry\Collectable\Traits\HasCollections;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasCollections;
}
Add an item to the collection.
$user->collection('favorites')->push($model);
Determine if an item exists in the collection for a given model.
$user->collection('favorites')->has($model);
Get the first item from the collection.
$user->collection('favorites')->first();
Retrieve an item from the collection by model.
$user->collection('favorites')->get($model);
Get all of the items from the collection.
$user->collection('favorites')->all();
Remove an item from the collection.
$user->collection('favorites')->forget($model);
Remove all items from the collection.
$user->collection('favorites')->flush();
Set the item-type that should be filtered by.
$user->collection('favorites')->type(Post::class)->all();

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@basecode.sh. All security vulnerabilities will be promptly addressed.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).