faustbrian/laravel-watchable

Watchable Polymorphic Eloquent Models for Laravel 5

2.2.0 2018-11-10 06:34 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 faustbrian/laravel-watchable

At last you need to publish and run the migration.

php artisan vendor:publish --provider="BrianFaust\Watchable\WatchableServiceProvider" && php artisan migrate

Usage

Setup a Model

<?php

namespace App;

use BrianFaust\Watchable\HasWatchlists;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasWatchlists;
}

Create a new watchlist for the $user-model

$user->createWatchlist([
    'title' => str_random(10),
    'description' => str_random(10),
    'type' => 'favorites',
]);

Add an item to a watchlist

$watchlist->addItem(Post::first());

Remove an item from a watchlist

$watchlist->removeItem(Post::first());

Testing

$ phpunit

Security

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

Credits

License

MIT © Brian Faust