Download the PHP package otifsolutions/aclmenu without Composer
On this page you can find all versions of the php package otifsolutions/aclmenu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download otifsolutions/aclmenu
More information about otifsolutions/aclmenu
Files in otifsolutions/aclmenu
Package aclmenu
Short Description An ACL Menu Package that includes User Roles, Permissions, Db based Menu Items, rights and permission based menu items
License MIT
Informations about the package aclmenu
aclmenu
Requirements
How to install the library
Install via Composer
Using Composer (Recommended)
Either run the following command in the root directory of your project:
Usage
-
Create User Role ( via Seeder )
-
Create Menu Items for Created
UserRole.$idis id of user role that is admin.Option type Description order_numberINT Number to show the item in sequence. parent_idINT Id of any item as a parent menu item. iconVarchar Icon of created menu item. nameVarchar Show the name of created menu item. routeVarchar Route access the intended page. generate_permissionisENUMtype of granted permission to the User Role, that are 'ALL', 'MANAGE_ONLY', 'READ_ONLY'.
Option Description All Allow user role to create, read, update, delete. MANAGE_ONLY Allow user role manage. READ_ONLY show that User can only read. -
- User role and permissions are created.
- Sync the permissions against menu items, so that user can have permissions to access the menu items.
-
Register the artisan command in database seeder in App/Database/Seeder/DatabaseSeeder.php;
Seeder run in this sequence.
-
Run the seeder to implement the changes
aclmenu:refresh
- This command seeds data in
Permissionmodel after checking the permission inMeuItemmodel. - Possible permissions are 'All', "READ" and "MANAGE_ONLY".
-
Default permission is
READ.ACLUserTrait
- Use
OTIFSolutions\ACLMenu\Traits\ACLUserTraitinUsermodel -
Following methods are used in this trait
Method relation Description user_role one-to-many (Inverse) This method returns user role from UserRolemodel to which user belongs.group one-to-many (Inverse) This method returns group from UserRoleGroupmodel to which user belongs.parent_team one-to-many (Inverse) This method returns parent_team from Teammodel to which it belongs.child_team one-to-one This method returns user who created the team. -
team
This method returns the user who created the team or parent_team.
-
hasPermission
This method checks if the user has permission or not to access the page.
- Returns
Trueif condition is true otherwise returnfalse. - Two Attributes are passed when calling the method.
- One is
permissionTypeString, possible values are READ, CREATE, UPDATE, or DELETE. - If no permissionTypeString is passed, READ is considered default.
- Another attribute is
permission, which is the route of page. - If no permission is passed, current permission is stored in session.
- Returns
-
hasPermissionMenuItem
- This method checks if the user has permission or not to access the menu item.
- Id of menu item is passed
menu_item_id. - Boolean value is returned. Possible values ar true or false.
-
getTeamOwnerAttribute
This method returns team owner from the team. return
$this['team']['owner']
Config
-
Returns
redirect_urlif user is unauthorized e.g./ -
It has a path of laravel
config.phpwhich returns the user from model. - Use this code to use config.
config('laravelacl.models.user')
Middleware
- Middleware handles the incoming request.
-
Middleware is set on route. such as
- If route has permission, intended page will be returned otherwise user is redirected.
How Middleware Works
-
If
Auth::Usernot found, homepage is returned. e.g./ -
If permission is null
- Get the current path info for the request.
$permission = $request->path();- Current permission is stored in the session using current path.
MODELS
-
MenuItem
Methode relation Description children one-to-many This method returns submenu items from MenuItemmodel. One menuitem can have one or more child items.permissions one-to-many This method returns list of permissions from Permissionmodel. One menuitem can have one or more permissions.user_roles many-To-many This method returns list of user_roles that belong to MenuItem. -
Permission
Method relation Description menu_item one-to-many (Inverse) This method return menuitem from MenuItemmodel that belongs to permission.type one-to-many (Inverse) This method return permission type which belongs to permission. -
PermissionType
- permission types has been created through seeder.
- These types are "READ", "CREATE", "UPDATE", "DELETE" and "MANAGE".
-
Team
Method relation Description owner one-to-many(Inverse) This method returns user who creates the team. A team can have only one owner. permissions belongToMany This method returns list of permissions from Permissionmodel that belongs toTeam.members one-to-many This method returns list of members. A team can have one or more members. user_roles one-to-many This method returns list of user_roles from UserRolemodel. Team can have one or more user roles. -
User Role
Method relation Description permissions belongsToMany This method returns list of permissionsfromPermissionmodel that belong to user_role.menu_items belongsToMany This method returns list of menu_items from MenuItembelong with user_role.team one-to-many (Inverse) This method returns team which belongs to user role. users one-to-many This method returns list of users from Usermodel. A user role can one or more users.groups belongsToMany This method returns groups that belong to UserRoleGroup. -
UserRoleGroup
Method relation Description users one-to-many This method returns list of users object. One user role group can have one or more users. user_roles belongsToMany This method returns list of user_roles from UserRolethat belong withUserRoleGroupmodel.Teams
Step. 1
-
Team is created with a
user_id.Team::updateOrCreate(['user_id' => 1]);
Step. 2
- Team owner creates user role.
Step. 3
- Owner assigns the permission to the created user role.
- Owner can assign the permission which are accessible by him.
Permissionis fetched fromPermissionmodel to assign permission,-
When owner assigns the permissions, these permissions will sync using following code.
$userRole->permissions()->sync($request['permissions']);
Step. 4
- Team members can be added by using the created user role.
Sidebar Creation
- Use the following class for side bar.
Content of sidebar
- Sidebar is created using the permissions which are assigned.
- __If the user_role is authenticated.__
- Loop begins and checks if user has permission to access the menuitem.
- Name of menu item appears on the sidebar.
-
Request::ischecks if the incoming request matches to the menuitem route then item becomes active.Request::is(strtolower(str_replace('/','',$menuItem['route']))) - If any menu item has submenu item, it will be opened after matching the request.
- If user has permission to access menuitem, the loop starts and matching submenu item becomes active.