PHP code example of jamesmills / watchable

1. Go to this page and download the library: Download jamesmills/watchable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jamesmills / watchable example snippets


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

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

class Book extends Model {
    use Watchable;
} 

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

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

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

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

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

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

public function pause(Order $order)
{
    $this->performAction('paused', $order);
    Notification::send($order->collectWatchers(), new OrderPaused($order));
}
bash
php artisan vendor:publish --provider="JamesMills\Watchable\WatchableServiceProvider" --tag="migrations"
php artisan migrate