PHP code example of questocat / laravel-rally

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

    

questocat / laravel-rally example snippets


\Questocat\Rally\RallyServiceProvider::class,

use Questocat\Rally\Traits\CanFollow

class User extends Model
{
    use CanFollow;
}

use Questocat\Rally\Traits\CanBeFollowed

class Post extends Model
{
    use CanBeFollowed;
}

use Questocat\Rally\Traits\Followable

class User extends Model
{
    use Followable;
}

$user->follow(1);  // App\User:class
$user->follow($user1);
$user->follow([1, 3]);
$user->follow(1, Post::class);

$user->unfollow(1);  // App\User:class
$user->unfollow($user1);
$user->unfollow([1, 2]);
$user->unfollow(1, Post::class);

$user->isFollowing(1);
$user->isFollowing($user2);
$user->isFollowing(2, Post::class);
$user->isFollowing($post, Post::class);

$user->toggleFollow(1);
$user->toggleFollow($user2);
$user->toggleFollow([2, 4]);
$user->toggleFollow([2, 4], Post::class);

$user->following;
$user->following()->get();    // It's the same thing as this
$user->following()->count();  // Get the total following

$user->isFollowedBy(3);
$user->isFollowedBy($user2);

$user->followers;
$user->followers()->get();    // It's the same thing as this
$user->followers()->count();  // Get the total followers

$user->isMutualFollow(1);
$user->isMutualFollow($user2);