Creating Roles
A role allows users to group users sharing the same attributes. This is frequently used for granting certain permissions to users who can perform the same task or permissions. While it's possible to create roles from the NexoPOS dashboard, it's still possible to create roles programmatically.
Creating A New Role
In order to create a new role, we'll use the App\Models\Role model that is available on NexoPOS. Typically, we'll proceed that way :
<?php
namespace App\Models\Role;
$role = new Role;
$role->name = __( 'Super Agent' );
$role->namespace = __( 'super-agent' );
$role->description = __( 'They are spy agent with black glasses' );
$role->save();
One created, the "$role" variable is an instance of the "Role" class, so it can be used to update or delete the role.
Get A Role By Namespace
The namespace attribute helps to fetch a role using a defined expression. Note that namespaces are meant not to have special characters or spaces to ease recognition by other developers (that's a convention). In the previous example, we've created a role with "super-agent" as the namespace. Here is how we'll retrieve that role.
<?php
use App\Models\Role;
$role = Role::namespace( 'super-agent' );