1. Go to this page and download the library: Download overtrue/laravel-subscribe 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/ */
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Overtrue\LaravelSubscribe\Traits\Subscriber;
class User extends Authenticatable
{
use Subscriber;
<...>
}
use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelSubscribe\Traits\Subscribable;
class Post extends Model
{
use Subscribable;
<...>
}
foreach($post->subscribers as $user) {
// echo $user->name;
}
// all
$user->subscriptions()->count();
// with type
$user->subscriptions()->withType(Post::class)->count();
// subscribers count
$post->subscribers()->count();
$users = User::withCount('subscriptions')->get();
foreach($users as $user) {
echo $user->subscriptions_count;
}