User follow feature for laravel application.
Version | Laravel | PHP Version |
---|---|---|
1.x | 6.x | >= 7.3 |
composer require sebastian-kennedy/laravel-follow -vvv
php artisan vendor:publish --provider="SebastianKennedy\\LaravelFollow\\FollowServiceProvider" --tag=config
php artisan vendor:publish --provider="SebastianKennedy\\LaravelFollow\\FollowServiceProvider" --tag=migrations
To allow an user to be followed or to follow other users, the user models have to make usage of a trait.
<?php
/*
* This file is part of the sebastian-kennedy/laravel-follow.
*
* (c) SebastianKennedy <sebastiankennedy@foxmail.com>
*
* This source file is subject to the MIT license that is bundled.
*/
namespace SebastianKennedy\LaravelFollow\Tests;
use Illuminate\Database\Eloquent\Model;
use SebastianKennedy\LaravelFollow\Behaviors\CanBeFollowBehavior;
use SebastianKennedy\LaravelFollow\Behaviors\CanFollowBehavior;
/**
* Class User.
*/
class User extends Model
{
use CanFollowBehavior;
use CanBeFollowBehavior;
}
$user = User::find(1);
$followings = $user->followings;
$user = User::find(1);
$follows = $user->follows;
$user1 = User::find(1);
$user2 = User::find(2);
$user1->hasFollowed($user2);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->follow($user2);
$user1 = User::find(1);
$users = User::whereIn('id', [2, 3, 4])->get();
$user1->followMany($users);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->specialFollow($user2);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->unFollow($user2);
$user1 = User::find(1);
$users = User::whereIn('id', [2, 3, 4])->get();
$user1->unFollowMany($users);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->cancelSpecialFollow($user2);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->toggleFollow($user2);
$user1 = User::find(1);
$user1->followers;
$user1 = User::find(1);
$user1->follwable;
$user1 = User::find(1);
$user2 = User::find(2);
$user1->isFollowedBy($user2);
$user1 = User::find(1);
$user2 = User::find(2);
$user2->follow($user1);
$user1->acceptFollow($user2);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->follow($user2);
$user2->rejectFollow($user1);
$user1 = User::find(1);
$user2 = User::find(2);
$user1->removeFollower($user2);
$user1 = User::find(1);
$users = User::whereIn('id', [2, 3, 4])->get();
$user1->removeManyFollowers($users);
MIT