PHP code example of anomaly / users-module

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

    

anomaly / users-module example snippets


use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;

$users = app(UserRepositoryInterface::class);

// Get user by ID
$user = $users->find(1);

// Get user by email
$user = $users->findByEmail('[email protected]');

// Get all users
$allUsers = $users->all();

// Check if user has permission
if (auth()->user()->hasPermission('posts.write')) {
    // User can write posts
}

// Check if user has role
if (auth()->user()->hasRole('admin')) {
    // User is admin
}

$users->create([
    'email' => '[email protected]',
    'username' => 'johndoe',
    'password' => 'secure_password',
    'display_name' => 'John Doe'
]);