Download the PHP package delgont/armor without Composer
On this page you can find all versions of the php package delgont/armor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download delgont/armor
More information about delgont/armor
Files in delgont/armor
Package armor
Short Description Larevel User - Permissions -Roles
License MIT
Homepage https://github.com/delgont/armor
Informations about the package armor
Delgont Armor
Armor is a Laravel package that provides a powerful access control system through roles and permissions, along with flexible backend authentication. This package allows login using either email, username, phone number, or another identifier, based on your preference.
Furthermore, the package enables user type-based access control through the HasUserTypes trait, offering fine-grained control over user access to specific routes and Blade views.
Features
- User Type-based Access Control - Enables route and Blade access based on user types.
- Multi-Authentication Credentials - Supports login with different fields, such as email, username, or phone number.
- Role and Permission Management - Assign roles and permissions to control access at a more granular level.
Email or username authentication
Access control using roles and permissions.
Composer
Laravel Framework 11.0+
Table Of Contents
- Installation
- Armor Configuration
- Multi-Credentials Authenticationion
- User Type-Based Access Control
- Blade Directives
- @usertype Blade Directive
- @can Blade Directive
- @rolecan Blade Directive
- Middlewares
- Artisan Commands
Installation
To install the Delgont/Armor package, use Composer:
After installation, publish the package configuration:
This command will publish the config/armor.php file, where you can set up custom configurations.
Configuration
Permission Delimiter Configuration
Permission Registrars Configuration
Adding Multi-Credentials Authenticationion
To allow users to log in with different credentials, such as email or username, email or phone.
-
Import the Trait: In your LoginController, import
the MultiAuthCredentials trait
: -
Setup the Login Field: In your LoginController, set up a method to allow dynamic field selection, if you want the user to login using phone or email then you can choose this function to retunr
phone_email
and this should be defined as the name for you login form input -
Define the
username
column name that will be used by Overriding the getSecondaryColumn() function in your LoginController. This function specifies the second column that will be used along with email during authentication. By default, it returns 'name', but you can modify it to use the column you intend to use. -
Implement Multi-Credentials: Use the
multiAuthCredentials()
method to check the user’s login input and determine the field (username or email, phone or email) they are attempting to log in with. Override the credentials method inLoginController
: - Login Form Input: Your login form should use the
username_email
field, which allows the user to enter theirusername or email
orphone_email
if you want to allow login withphone or email
LoginController
User Type-Based Access Control
User type-based access control allows you to restrict specific routes and Blade templates based on user roles, such as "master" or "employee."
-
add usertype & user_id columns to your authenticatable migration
-
Add Delgont\Auth\Concerns\HasUserTypes Trait to user model.
- Your usertype models
Blade Directives
@usertype Blade Directive
The @usertype Blade directive allows you to check if the currently authenticated user matches any of the specified user types. This directive can be used to conditionally render content based on the user's type, providing a flexible way to manage permissions and access control in your views.
Usage
@can Blade Directive
Usage
@rolecan Blade Directive
The @rolecan directive allows you to check if the authenticated user's role has the specified permissions before granting access to a particular section of your Blade view. This directive is particularly useful for managing access control based on user roles and their associated permissions.
Your Authenticatable models must be limited to a single role, use Delgont\Armor\Concerns\ModelHasSingleRole
and migrations must have role_id
<h6 style="color: #FF6347;"">Usage
- Your login View.
Middlewares
1. Track Page Access
track.page-access:page-name
This middleware is responsible for tracking the times a page has been access on a Laravel application. It logs information about page views, including the IP address, User-Agent, and visit count for each page. If a user accesses the same page multiple times, the middleware will update the count and store the latest User-Agent information.
Usage
To use this middleware, it should be registered in your app/Http/Kernel.php file or applied directly to specific routes in the routes/web.php file.
Artisan Commands
Role Artisan Commands
Role Artisan Commands
Role Artisan Commands
Role Artisan Commands
All versions of armor with dependencies
illuminate/support Version ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
illuminate/auth Version ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
illuminate/database Version ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
laravel/helpers Version ^1.5.0 || 1.6.0 || 1.7.0