Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 1.84 KB

users.md

File metadata and controls

85 lines (60 loc) · 1.84 KB

Users and Permissions

Users for Administrative part are separated from mail site. They are stored in own database and has own functionality.

The database locates in database/admin_users.db file. Do not forget to add it to your .gitignore file.

Roles

Backend Users has roles. By default there are 2 roles:

  • Superuser
  • Admin

Superuser is hidden and can do all possible things for the application. You can add additional roles in the published configuration file.

// config/admin.php

'roles' => [
    Role::ADMIN => 'Main Administrator with all Application permissions.',
    'moderator' => 'Site worker.',
],

Now you can use moderator role in gates and/or policies.

// AppServiceProvider

Gate::define('moderator', static function ($user): bool {
    $allowed_roles = [Role::SUPER, Role::ADMIN, 'moderator'];

    return rescue(
        static function () use (&$allowed_roles, &$user): bool {
            return \in_array($user->role, $allowed_roles, true);
        },
        false
    );
});

// ...

auth('admin')->user()->can('moderator');

Guards

The package registers admin guard.

auth('admin')->user();

All controllers must be protected with \SP\Admin\Http\Middleware\Authenticate:admin middleware.

// Controller

public function __construct()
{
    $this->middleware('\SP\Admin\Http\Middleware\Authenticate:admin');
}

To simplify development of backend controllers it is recommended to extend them from \SP\Admin\Http\Controllers\AdminController (code).

Policies

When you creating policies extend them from AbstractPolicy. This always gives access for superuser.


Table of contents