All Projects → jamesmills → Watchable

jamesmills / Watchable

Licence: mit
Enable users to watch various models in your application.

Projects that are alternatives of or similar to Watchable

Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+204.62%)
Mutual labels:  eloquent, laravel, laravel-5-package, package
Guardian
Eloquent Guardian is a simple permissions system for your users. While there are many other packages for permissions, this one solves everything in the most eloquent way.
Stars: ✭ 121 (+86.15%)
Mutual labels:  eloquent, laravel, package
Laravel Likeable
Rate Eloquent models with Likes and Dislikes in Laravel. Development moved to Laravel Love package!
Stars: ✭ 95 (+46.15%)
Mutual labels:  eloquent, laravel, package
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+4150.77%)
Mutual labels:  eloquent, laravel, laravel-5-package
Laravel Gitscrum
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
Stars: ✭ 2,686 (+4032.31%)
Mutual labels:  laravel, laravel-5-package, package
Laravel Nullable Fields
Handles saving empty fields as null for Eloquent models
Stars: ✭ 88 (+35.38%)
Mutual labels:  eloquent, laravel, package
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+266.15%)
Mutual labels:  eloquent, laravel, laravel-5-package
Laravel Ownership
Laravel Ownership simplify management of Eloquent model's owner.
Stars: ✭ 71 (+9.23%)
Mutual labels:  eloquent, laravel, package
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+552.31%)
Mutual labels:  eloquent, laravel, laravel-5-package
Laravel Cascade Soft Deletes
Cascading deletes for Eloquent models that implement soft deletes
Stars: ✭ 498 (+666.15%)
Mutual labels:  eloquent, laravel, package
Laravel Ban
Laravel Ban simplify blocking and banning Eloquent models.
Stars: ✭ 572 (+780%)
Mutual labels:  eloquent, laravel, package
Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (+21.54%)
Mutual labels:  laravel, laravel-5-package, package
Laravel Translatable
A Laravel package for multilingual models
Stars: ✭ 624 (+860%)
Mutual labels:  eloquent, laravel, package
Plans
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Stars: ✭ 326 (+401.54%)
Mutual labels:  eloquent, laravel, package
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (+816.92%)
Mutual labels:  eloquent, laravel, package
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-81.54%)
Mutual labels:  eloquent, laravel, laravel-5-package
Laravel Packager
A cli tool for creating Laravel packages
Stars: ✭ 1,049 (+1513.85%)
Mutual labels:  laravel, package
Fluent Facebook
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax
Stars: ✭ 49 (-24.62%)
Mutual labels:  laravel, laravel-5-package
Laravel Wang Editor
wangEditor for Laravel
Stars: ✭ 52 (-20%)
Mutual labels:  laravel, laravel-5-package
Laravel Reviewable
Adds a reviewable feature to your laravel app.
Stars: ✭ 57 (-12.31%)
Mutual labels:  laravel, package

Laravel Watchable

Packagist Packagist Travis Packagist Buy us a tree Treeware (Trees)

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

Installation

Pull in the package using Composer

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.

Include the service provider within app/config/app.php.

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

Publish and run the database migrations

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.

https://jamesmills.co.uk/2017/10/22/laravel-watchable-package

How to use

Prepare your model to be watched

Simply add the watchable trait to your model

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

class Book extends Model {
    use Watchable;
} 

Available methods

Watch a model

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

Unwatch a model

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

Toggle the watching of a model

$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.

$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

@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

$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.

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.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].