PHP code example of ohkannaduh / groups

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

    

ohkannaduh / groups example snippets


    'providers' => [
    ...
        /*
        * Package Service Providers...
        */
        OhKannaDuh\Groups\GroupsServiceProvider::class
    ...
    ],

...
use OhKannaDuh\Groups\Traits\Groupable;
use OhKannaDuh\Groups\Contracts\GroupableContract;
...
class User extends Model implements GroupableContract
{
    use Groupable;
    ...
}

$group->addUser($user);

$group->addUsers($users);

$group->removeUser($user);

$group->removeUsers($users);

$group->contains($user)

$group->users;

$user->groups;

$group->messages;

$message->user;

$message->group

public function canAddToGroup(\OhKannaDuh\Groups\Model\Group $group): bool

public function canAddToGroup(\OhKannaDuh\Groups\Model\Group $group): bool
{
    foreach ($group->users as $user) {
        /**
         * This user has been blocked or has blocked the other user.
         * Don't add them to the group.
         */
        if ($user->isBlocked($this) === true) {
            return false;
        }
    }

    return true;
}

public function canRemoveFromGroup(\OhKannaDuh\Groups\Model\Group $group): bool

public function canRemoveFromGroup(\OhKannaDuh\Groups\Model\Group $group): bool
{
    # Don't remove the user if they are the last remaining group member
    return count($group) > 1;
}

public function canSendMessageToGroup(\OhKannaDuh\Groups\Model\Group $group): bool

public function canSendMessageToGroup(\OhKannaDuh\Groups\Model\Group $group): bool
{
    # Only users that are admins can send messages to groups
    return $this->isAdmin();
}
sh
php artisan vendor:publish --provider="OhKannaDuh\Groups\GroupsServiceProvider"
sh
php artisan migrate