1. Go to this page and download the library: Download overtrue/laravel-follow 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/ */
overtrue / laravel-follow example snippets
use Overtrue\LaravelFollow\Traits\Follower;
class User extends Authenticatable
{
use Follower;
<...>
}
use Overtrue\LaravelFollow\Traits\Followable;
class User extends Authenticatable
{
use Followable;
<...>
}
use Overtrue\LaravelFollow\Traits\Followable;
class Channel extends Model
{
use Followable;
<...>
}
foreach($user->followings()->with('followable')->get() as $following)
{
$following->created_at; // followed at
$following->followable->nickname; // the user attributes
}
foreach($user->followers()->with('followers')->get() as $follower)
{
$follower->created_at; // followed at
$follower->follower->nickname; // the user attributes
}
public function needsToApproveFollowRequests()
{
// Your custom logic here
return (bool) $this->private;
}
// followings count
$user->followings()->count();
$user->approvedFollowings()->count();
$user->notApprovedFollowings()->count();
// with query where
$user->followings()->where('gender', 'female')->count();
// followers count
$user->followers()->count();
$user->approvedFollowers()->count();
$user->notApprovedFollowers()->count();
$users = User::withCount(['followings', 'followables'])->get();
// or
$users = User::withCount(['approvedFollowings', 'approvedFollowers'])->get();
foreach($users as $user) {
// $user->followings_count;
// $user->followers_count;
// or
// $user->approved_followings_count;
// $user->approved_followers_count;
}