2017 © Pedro Peláez
 

library watchable

A package to allow your Models to become watchable by a User

image

jamesmills/watchable

A package to allow your Models to become watchable by a User

  • Sunday, February 18, 2018
  • by jamesmills
  • Repository
  • 3 Watchers
  • 57 Stars
  • 337 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 7 Versions
  • 23 % Grown

The README.md

Laravel Watchable

Packagist Packagist Travis Packagist Buy us a tree Treeware (Trees), (*1)

Enable users to watch various models in your application. - Designed to work with Laravel Eloquent models - Just add the trait to the model you would like to be watchable - Watches are unique for one model and one user - Events are fired on watched and unwatched methods - Built to work with Laravel Notifications, (*2)

Installation

Pull in the package using Composer, (*3)

composer require jamesmills/watchable

Note: If you are using Laravel 5.5, the next step for provider are unnecessary. Laravel Watchable supports Laravel Package Discovery., (*4)

Include the service provider within app/config/app.php., (*5)

'providers' => [
    ...
    JamesMills\Watchable\WatchableServiceProvider::class,
],

Publish and run the database migrations, (*6)

php artisan vendor:publish --provider="JamesMills\Watchable\WatchableServiceProvider" --tag="migrations"
php artisan migrate

Sample Usage and Boilerplate

I wrote a blog post to give you some boilerplate code that you can use in your application to wrap around the Laravel Watchable package., (*7)

https://jamesmills.co.uk/2017/10/22/laravel-watchable-package, (*8)

How to use

Prepare your model to be watched

Simply add the watchable trait to your model, (*9)

use Illuminate\Database\Eloquent\Model;
use JamesMills\Watchable\Traits\Watchable;

class Book extends Model {
    use Watchable;
} 

Available methods

Watch a model, (*10)

$book = Book::first();
$book->watch();  

Unwatch a model, (*11)

$book = Book::first();
$book->unwatch(); 

Toggle the watching of a model, (*12)

$book = Book::first();
$book->toggleWatch(); 

You can optionally send the $user_id if you don't want to use the built in auth()->user()->id functionality., (*13)

$book = Book::first();
$book->watch($user_id);
$book->unwatch($user_id); 
$book->toggleWatch($user_id); 

Find out if the current user is watching the model, (*14)

@if ($book->isWatched())
    {{ You are watching this book }}
@else
    {{ You are NOT watching this book }}
@endif

Get a collection of the user who are watching a model, (*15)

$book = Book::first();
$book->collectWatchers(); 

Use with Notifications

One of the main reasons I built this package was to scratch my own itch with an application I am building. I wanted to be able to send notifications to user who were watching a given model and I also wanted to allow users to be able to watch a number of different models., (*16)

public function pause(Order $order)
{
    $this->performAction('paused', $order);
    Notification::send($order->collectWatchers(), new OrderPaused($order));
}

License

This package is 100% free and open-source, under the MIT license. Use it however you want., (*17)

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats., (*18)

The Versions

18/02 2018

dev-master

9999999-dev https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent php7 package watch like likeable laravel-5-package watchable

18/02 2018

1.0.5

1.0.5.0 https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent php7 package watch like likeable laravel-5-package watchable

02/11 2017

1.0.4

1.0.4.0 https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent php7 package watch like likeable laravel-5-package watchable

10/10 2017

1.0.3

1.0.3.0 https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent php7 package watch like likeable laravel-5-package watchable

15/09 2017

1.0.2

1.0.2.0 https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent php7 package watch like likeable laravel-5-package watchable

10/09 2017

1.0.1

1.0.1.0 https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent php7 package watch like likeable laravel-5-package watchable

31/08 2017

1.0.0

1.0.0.0 https://github.com/jamesmills/watchable

A package to allow your Models to become watchable by a User

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel watch like watchable