PHP code example of hypefactors / laravel-follow

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

    

hypefactors / laravel-follow example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Hypefactors\Laravel\Follow\Traits\CanFollow;
use Hypefactors\Laravel\Follow\Contracts\CanFollowContract;

class User extends Model implements CanFollowContract
{
    use CanFollow;
}



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Hypefactors\Laravel\Follow\Traits\CanBeFollowed;
use Hypefactors\Laravel\Follow\Contracts\CanBeFollowedContract;

class Company extends Model implements CanBeFollowedContract
{
    use CanBeFollowed;
}

$company = Company::find(1);

$user = User::find(1);
$user->follow($company);

$user = User::find(1);

$company = Company::find(1);
$company->addFollower($user);

$companies = Company::whereIn('id', [1, 3, 10])->get();

$user = User::find(1);
$user->followMany($companies);

$users = User::whereIn('id', [1, 3, 10])->get();

$company = Company::find(1);
$company->addManyFollowers($users);

$company = Company::find(1);

$user = User::find(1);
$user->unfollow($company);

$user = User::find(1);

$company = Company::find(1);
$company->removeFollower($user);

$companies = Company::whereIn('id', [1, 3, 10])->get();

$user = User::find(1);
$user->unfollowMany($companies);

$users = User::whereIn('id', [1, 3, 10])->get();

$company = Company::find(1);
$company->removeManyFollowers($users);

$company = Company::find(1);

$user = User::find(1);
$user->isFollowing($company);

$user = User::find(1);

$company = Company::find(1);
$company->hasFollower($user);

$user = User::find(1);

if ($user->hasFollowings()) {
    echo "User is following {$user->followings->count()} entities.";
}

$company = Company::find(1);

if ($company->hasFollowers()) {
    echo "Company has {$company->followers->count()} followers.";
}

$user = User::find(1);

$followings = $user->followings

$company = Company::find(1);

$followers = $company->followers

$user = User::find(1);

$followings = $user->followings()->whereFollowableType(Company::class)->get();

$company = Company::find(1);

$followers = $company->followers()->whereFollowerType(User::class)->get();

php artisan migrate