PHP code example of wimil / followers

1. Go to this page and download the library: Download wimil/followers 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/ */

    

wimil / followers example snippets


Wimil\Followers\Provider::class

$ php artisan migrate

use Wimil\Followers\Traits\Followable;

class User extends Model
{
    use Followable;
}

$bob = User::find(1);
$alin = User::find(2);

$bob->follow($alin);
$alin->follow($bob);
$bob->follow([2, 'App\User']);
$alin->follow([1, 'App\User']);

$bob->toggleFollow($alin);
$alis->toggleFollow($bob);
$bob->toggleFollow([2, 'App\User']);
$alin->toggleFollow([1, 'App\User']);


use Wimil\Follow\Traits\CanFollow;

class User extends Model
{
    use CanFollow;
}

$user = User::find(1);
$page = Page::find(1);

$user->follow($page);
$user->toggleFollow($page);
$user->unfollow($page);
$user->isFollowing($page);

use Wimil\Follow\Traits\CanBeFollowed;

class Page extends Model
{
    use CanBeFollowed;
}

$user = User::find(1);
$page = Page::find(1);

$page->addFollower($user);
$page->deleteFollower($user);
$page->toggleFollower($user);
$page->isFollowedBy($user);

use Wimil\Followers\Model\Follower as BaseFollower;

class Follower extends BaseFollower
{
    // ...
}

'Follow' => Wimil\Followers\Facades\Follow::class;

$bob = User::find(1);
$alin = User::find(2);

Follow::attach($bob, $alin);
Follow::attach($alin, $bob);
Follow::attach([1, 'App\User'], [2, 'App\User']);
Follow::attach([2, 'App\User'], [1, 'App\User']);

Follow::detach($bob, $alin);
Follow::toggle($bob, $alin);
Follow::exists($bob, $alin);