Biskuit comes with a prepared signup procedure and a powerful user manager. With all of these users in your system, your extension can easily make use of roles and permissions.
A user is a representation of a person registered with your site and identified by their username. The status of a user account can be active, blocked or new. Users can log in to your site or the admin area. Not all users’ accounts are allowed to access the admin area.
Permissions define the actions a user can perform . A permission is identified by a name, for example
user: access admin area. Permission names should be descriptive and start with the name of the according module, e.g.
user: for the user module.
Roles group together several user accounts. All users with the same role share the same permissions. Roles are also used to manage access to elements of your site’s content. A user can belong to zero, one or multiple roles. A role can have any number of users assigned to it. Biskuit comes with the default roles Anonymous, Authenticated and Administrator and allows you to create as many more as you need.
Roles are very flexible in how they can be used. You can create specific content that is only accessible by selected users.
This item will now be visible only to logged in users of the Premium role.
Note Your administrator account won’t be able to see this content either, unless you add the user to the Premium role as well or enable Administrator in the Restrict access settings.
To add a permission to the system area, which can then be assigned to a role, use the
permissions keyword in the
index.php file of an extension.
Use speaking permission names. The convention is to start with the name of the extension and then have a short phrase describing the permission, all lowercase. The
title is the string displayed in the browser. The
_() call makes sure this string is translatable.
'permissions' => [ 'hello: manage settings' => [ 'title' => _('Manage settings') ], ],
Check, if the user has a role of a specific ID.
$role_id = 4; App::user()->hasRole($role_id);
Check, if the user has a role of a specified name.
$role_name = "Editor"; $role = Role::where('name = ?', [$role_name])->first(); App::user()->hasRole($role->id);