# Access Control List
# Introduction
In addition to providing authentication services out of the box, Bagisto also offers an Access Control List (ACL) functionality. This feature allows administrators to control user access to different parts of Bagisto.
# Directory Structure
To configure the ACL, follow these steps:
Create a new file named
acl.php
in thepackages/Webkul/Blog/src/Config
folder of your package.└── packages └── Webkul └── Blog └── src ├── ... └── Config ├── acl.php └── ...
Add the following code to
acl.php
:<?php return [ [ 'key' => 'blog', 'name' => 'blog', 'route' => 'blog.admin.index', 'sort' => 2 ] ];
In the above code, we have defined an array for each menu item with the parameters (key, name, route, and sort). You need to define the menus you want to include in the ACL here.
# Merge Configuration
To merge the ACL configuration, follow these steps:
Open the
BlogServiceProvider
class in theWebkul\Blog\Providers
namespace.In the
register
method, add the following code to merge the ACL configuration:<?php namespace Webkul\Blog\Providers; use Illuminate\Support\ServiceProvider; class StripeServiceProvider extends ServiceProvider { /** * Register services. * * @return void */ public function register() { //... $this->mergeConfigFrom( dirname(__DIR__) . '/Config/acl.php', 'acl' ); } }
This will merge the ACL configuration with the existing configuration.
After making the changes, run the following command to cache the latest changes:
php artisan optimize
This will ensure that the latest ACL configuration is used.
You can now check the updated ACL configuration in the admin panel:
Admin ACL Output
# Checking Roles and Permissions
To check roles and permissions, follow these steps:
Open the
Admin
model in theWebkul\User\Models
namespace.In this model, you will find a relationship binding with the
Role
model in the same namespace. You can use this relationship to access all the permissions of the current user.We have provided the
bouncer()
helper function, which allows you to check permissions. Use the following code to check if the current user has a specific permission:bouncer()->hasPermission($permission)
Replace
$permission
with the actual permission you want to check.
By following these steps, you can configure and manage the Access Control List (ACL) in Bagisto.