PHPackages                             php-soft/laravel-users - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. php-soft/laravel-users

ActiveProject[Framework](/categories/framework)

php-soft/laravel-users
======================

Laravel Users Module

v1.0.0(9y ago)195.0k10[6 issues](https://github.com/php-soft/laravel-users/issues)[1 PRs](https://github.com/php-soft/laravel-users/pulls)MITPHPPHP &gt;=5.5.9

Since Nov 26Pushed 9y ago8 watchersCompare

[ Source](https://github.com/php-soft/laravel-users)[ Packagist](https://packagist.org/packages/php-soft/laravel-users)[ RSS](/packages/php-soft-laravel-users/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (4)Used By (0)

Laravel Users Module
====================

[](#laravel-users-module)

[![Build Status](https://camo.githubusercontent.com/d147864540a1badd613f77cd0eb0a875bd8e5edfc0bd4e848a20b6c7b8d83f25/68747470733a2f2f7472617669732d63692e6f72672f7068702d736f66742f6c61726176656c2d75736572732e737667)](https://travis-ci.org/php-soft/laravel-users)

> This module is use JWTAuth and ENTRUST libraries
>
> 1.  (JSON Web Token)
> 2.  (Role-based Permissions)

1. Installation
---------------

[](#1-installation)

Install via composer - edit your `composer.json` to require the package.

```
"require": {
    // ...
    "php-soft/laravel-users": "dev-master",
}
```

Then run `composer update` in your terminal to pull it in. Once this has finished, you will need to add the service provider to the `providers` array in your `app.php` config as follows:

```
'providers' => [
    // ...
    PhpSoft\ArrayView\Providers\ArrayViewServiceProvider::class,
    PhpSoft\Users\Providers\UserServiceProvider::class,
    Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,
    Zizaco\Entrust\EntrustServiceProvider::class,
]
```

Next, also in the `app.php` config file, under the `aliases` array, you may want to add facades.

```
'aliases' => [
    // ...
    'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
    'Entrust' => Zizaco\Entrust\EntrustFacade::class,
]
```

You will want to publish the config using the following command:

```
$ php artisan vendor:publish --provider="PhpSoft\Users\Providers\UserServiceProvider"
```

***Don't forget to set a secret key in the jwt config file!***

I have included a helper command to generate a key as follows:

```
$ php artisan jwt:generate
```

this will generate a new random key, which will be used to sign your tokens.

2. Migration and Seeding
------------------------

[](#2-migration-and-seeding)

Now generate the migration:

```
$ php artisan ps-users:migrate
```

It will generate the `_entrust_setup_tables.php` migration. You may now run it with the artisan migrate command:

```
$ php artisan migrate
```

Running Seeders with command:

```
$ php artisan db:seed --class=UserModuleSeeder
```

3. Usage
--------

[](#3-usage)

### 3.1. Authenticate with JSON Web Token

[](#31-authenticate-with-json-web-token)

You need to change class `App\User` to inherit from `PhpSoft\Users\Models\User` as follows:

```
namespace App;

// ...
use PhpSoft\Users\Models\User as PhpSoftUser;

class User extends PhpSoftUser implements AuthenticatableContract, CanResetPasswordContract
{
    // ...

    // You need allows fill attributes as follows
    protected $fillable = [
        'name',
        'email',
        'password',
        'username',
        'location',
        'country',
        'biography',
        'occupation',
        'website',
        'image',
        'birthday',
        'gender'
    ];

    // ...
}
```

Remove middlewares in `app/Http/Kernel.php`

- `\App\Http\Middleware\EncryptCookies::class`
- `\App\Http\Middleware\VerifyCsrfToken::class`

Add route middlewares in `app/Http/Kernel.php`

```
protected $routeMiddleware = [
    // ...
    'jwt.auth' => \PhpSoft\Users\Middleware\Authenticate::class,
    'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
];
```

Add routes in `app/Http/routes.php`

```
Route::post('/auth/login', '\PhpSoft\Users\Controllers\AuthController@login');
Route::group(['middleware'=>'auth'], function() { // use middleware jwt.auth if use JSON Web Token
    Route::post('/auth/logout', '\PhpSoft\Users\Controllers\AuthController@logout');
    Route::get('/me', '\PhpSoft\Users\Controllers\UserController@authenticated');
    Route::patch('/me', '\PhpSoft\Users\Controllers\UserController@updateProfile');
    Route::put('/me/password', '\PhpSoft\Users\Controllers\PasswordController@change');

});
Route::post('/passwords/forgot', '\PhpSoft\Users\Controllers\PasswordController@forgot');
Route::post('/passwords/reset', '\PhpSoft\Users\Controllers\PasswordController@reset');
Route::group(['middleware'=>'routePermission'], function() {

    Route::post('/users', '\PhpSoft\Users\Controllers\UserController@store');
    Route::get('/users', '\PhpSoft\Users\Controllers\UserController@index');
    Route::get('/users/{id}', '\PhpSoft\Users\Controllers\UserController@show');
    Route::delete('/users/{id}', '\PhpSoft\Users\Controllers\UserController@destroy');
    Route::patch('/users/{id}', '\PhpSoft\Users\Controllers\UserController@update');
    Route::post('/users/{id}/block', '\PhpSoft\Users\Controllers\UserController@block');
    Route::post('/users/{id}/unblock', '\PhpSoft\Users\Controllers\UserController@unblock');
});
```

Apache seems to discard the Authorization header if it is not a base64 encoded user/pass combo. So to fix this you can add the following to your apache config

```
RewriteEngine On

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

```

Alternatively you can include the token via a query string

```
http://api.mysite.com/me?token={yourtokenhere}

```

### 3.2. Role-based Permissions

[](#32-role-based-permissions)

Use the `UserTrait` trait in your existing `App\User` model. For example:

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use PhpSoft\Users\Models\UserTrait;

class User extends Model
{
    use UserTrait; // add this trait to your user model
    // ...
}
```

Create `Role` and `Permission` follows

```
// create role admin (default this role has been created on UserModuleSeeder)
$admin = new Role();
$admin->name         = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description  = 'User is allowed to manage and edit other users'; // optional
$admin->save();

// role attach alias
$user->attachRole($admin); // parameter can be an Role object, array, or id

// or eloquent's original technique
$user->roles()->attach($admin->id); // id only

// create permission
$createPost = new Permission();
$createPost->name         = 'create-post';
$createPost->display_name = 'Create Posts'; // optional
$createPost->description  = 'create new blog posts'; // optional
$createPost->save();

$admin->attachPermission($createPost);
// equivalent to $admin->perms()->sync(array($createPost->id));
```

Now we can check for roles and permissions simply by doing:

```
$user->hasRole('owner');   // false
$user->hasRole('admin');   // true
$user->can('edit-user');   // false
$user->can('create-post'); // true
```

Both `hasRole()` and `can()` can receive an array of roles &amp; permissions to check:

```
$user->hasRole(['owner', 'admin']);       // true
$user->can(['edit-user', 'create-post']); // true
```

### 3.3 Forgot password

[](#33-forgot-password)

To send mail forgot password,

- You need to add address and name of sender in `config\mail.php` as follows:

```
'from' => ['address' => 'no-reply@example.com', 'name' => 'System'],
```

- You need to create email view: Create `password.blade.php` file in folder `resources\views\emails` with contents as follows:

```
You are receiving this e-mail because you requested resetting your password to domain.com
Please click this URL to reset your password: http://domain.com/passwords/reset?token={{$token}}
```

You can change contents of this view for your using.

By other way, you can use other view and config `password.email` in `config\auth.php`:

```
    'password' => [
        'email' => 'emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
```

### 3.4 Middlewares

[](#34-middlewares)

#### PhpSoft\\Users\\Middleware\\Permission

[](#phpsoftusersmiddlewarepermission)

This middleware is used to check permission for an action.

Add route middlewares in app/Http/Kernel.php

```
protected $routeMiddleware = [
    // ...
    'permission' => \PhpSoft\Users\Middleware\Permission::class,
];
```

Usage

```
Route::post('/posts', [
    'middleware' => 'permission:create-post', // Only allows user have create-post permission (or have admin role) access to this route
    function () {
        // ...
    }
]);
```

#### PhpSoft\\Users\\Middleware\\RoutePermission

[](#phpsoftusersmiddlewareroutepermission)

This middleware is used to check permission for a route dynamic by database.

Add route middlewares in app/Http/Kernel.php

```
protected $routeMiddleware = [
    // ...
    'routePermission' => \PhpSoft\Users\Middleware\RoutePermission::class,
];
```

Usage

```
Route::group(['middleware'=>'routePermission'], function() {
    Route::post('/blog', function () {
        //
    });
});
```

Require permission for a route as follows

```
// require permissions
PhpSoft\Users\Models\RoutePermission::setRoutePermissions('POST /blog', ['create-blog']);

// require roles
PhpSoft\Users\Models\RoutePermission::setRouteRoles('POST /blog', ['creator']);

// require permissions or roles
PhpSoft\Users\Models\RoutePermission::setRoutePermissionsRoles('POST /blog', ['create-blog'], ['creator']);
```

#### PhpSoft\\Users\\Middleware\\Validate

[](#phpsoftusersmiddlewarevalidate)

This middleware is used to check validate for fields on different applications which use this package.

Add route middlewares in app/Http/Kernel.php

```
protected $routeMiddleware = [
    // ...
    'validate'   => \PhpSoft\Users\Middleware\Validate::class,
];
```

Usage

```
Route::post('/user', ['middleware'=>'validate: App\Http\Validators\UserValidate',
    function () {
        //
    }
]);
```

With `App\Http\Validators\UserValidate`, it's class which you need to declare in route. This class is used to declare rules to validate.

You can also use other class to declare rules for validate in your application but It have to implements `PhpSoft\Users\Contracts\Validator` class.

For example, I declared rules in `App\Http\Validators\UserValidate` class as follows:

```
use PhpSoft\Users\Contracts\Validator;

/**
 * User Validate
 *
 * return array
 */
class UserValidate implements Validator
{
    /**
     * Custom validator
     *
     * @return boolean
     */
    public static function boot($request)
    {

        IlluminateValidator::extend('validate_name', function($attribute, $value, $parameters) {

                return $value == 'validate_name';
            }, 'The name is in valid.'
        );
    }

    /**
     * Declare rules
     *
     * @return array
     */
    public static function rules()
    {
        return [
            'name'     => 'required|max:255|validate_name',
            'email'    => 'required|email',
            'password' => 'required|confirmed|min:6'
        ];
    }
}
```

Here, you will declare fields that you want to validate them in `rules()` function. And You can also custom validator fields that you want by declare them in `boot()` function.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3647d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e69b90fa878951d2378a9e7480d6db4de59c30ce54eede012dbfee60da1a5bf1?d=identicon)[huytbt](/maintainers/huytbt)

---

Top Contributors

[![huytbt](https://avatars.githubusercontent.com/u/7126782?v=4)](https://github.com/huytbt "huytbt (101 commits)")[![gghoantt](https://avatars.githubusercontent.com/u/13842780?v=4)](https://github.com/gghoantt "gghoantt (74 commits)")[![toancong](https://avatars.githubusercontent.com/u/5398771?v=4)](https://github.com/toancong "toancong (2 commits)")

---

Tags

laravelmoduleUsers

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/php-soft-laravel-users/health.svg)

```
[![Health](https://phpackages.com/badges/php-soft-laravel-users/health.svg)](https://phpackages.com/packages/php-soft-laravel-users)
```

###  Alternatives

[mhmiton/laravel-modules-livewire

Using Laravel Livewire in Laravel Modules package with automatically registered livewire components for every modules.

236409.6k9](/packages/mhmiton-laravel-modules-livewire)[pingpong/modules

Laravel Modules

592188.7k13](/packages/pingpong-modules)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
