Download the PHP package erag/laravel-role-permission without Composer

On this page you can find all versions of the php package erag/laravel-role-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-role-permission

Laravel Role-Permission

Screenshot 2024-10-04 at 10 34 23 PM
[![Packagist License](https://img.shields.io/badge/Licence-MIT-blue)](https://github.com/eramitgupta/laravel-role-permission/blob/main/LICENSE) [![Latest Stable Version](https://img.shields.io/packagist/v/erag/laravel-role-permission?label=Stable)](https://packagist.org/packages/erag/laravel-role-permission) [![php](https://img.shields.io/packagist/php-v/erag/laravel-role-permission.svg?color=purple)](https://packagist.org/packages/erag/laravel-role-permission) [![Total Downloads](https://img.shields.io/packagist/dt/erag/laravel-role-permission.svg?label=Downloads)](https://packagist.org/packages/erag/laravel-role-permission)

Getting Started

Install the package via Composer

Step 1: Add Trait to User Model

Before configuring the database and publishing the role-permission files, add the HasPermissionsTrait to define in your User model. This trait is essential for handling roles and permissions in your application.

Step 2: Database Configuration

Before proceeding with the setup, ensure that your database connection is properly configured in your .env file. Example configuration:

Make sure to replace your_database_name, your_database_user, and your_database_password with your actual database credentials.

Step 3: Register the Service Provider

For Laravel v11.x

Ensure the service provider is registered in your /bootstrap/providers.php file:

For Laravel v8.x, v9.x, v10.x

Ensure the service provider is registered in your config/app.php file:

Step 4: Publish Role-Permission Files

Once the database is configured, publish the required migration with a single command:

You can also run migrations and seeders:

Or both

Upgrade New Version Command

To upgrade the package to a new version:

Available Functions Documentation

Permission Management

givePermissionsTo(array $permissions, string|array|null $expiresAt = null): static

Assigns permissions to a user with optional expiration dates.

detachPermissions(string|array $permissions): static

Removes specified permissions from a user.

hasPermissionTo(...$permissions): bool

Checks if user has specific permissions through roles or direct assignment.

hasPermissions(string|array $permissions): bool

Verifies user has all specified permissions.

Role Management

assignRole(string|array $roles): static

Assigns roles to a user.

hasRole(...$roles): bool

Checks if user has any of the specified roles.

Helper Methods

hasPermissionThroughRole($permission): bool

Checks if user has permission through assigned roles.

roles()

Relationship method for user roles.

permissions()

Relationship method for user permissions.

Using Role-Based Permissions

You can now easily check user permissions within your application logic: You can also use the helper method:

OR

Retrieve Permissions and Roles

Using Role-Based Checks

Blade Directives

Middleware Usage

How to Use Permissions Expiration

The permission expiration feature allows you to set temporary access that expires automatically after a certain period or, by setting the expiration date to null, to allow unlimited access. This feature is useful for setting up both temporary and permanent permissions.

Adding Permissions with Expiration

  1. Assign Permission with Expiration: Use the givePermissionsTo method to assign a permission with an expiration date.

In this example, the post-create permission will be assigned to the user and expire after 30 days.

  1. Assign Multiple Permissions with Different Expirations: If you need to assign multiple permissions with individual expiration dates, pass an associative array where the keys are permission names, and the values are the expiration dates.

How to Use without Permissions Expiration

  1. Assign Permission with Unlimited Duration: Assign permissions without an expiration by setting the expiration to null. This will give the user unlimited access to the permission.

OR

Example Seeder for Roles and Permissions

Here's an example RolePermissionSeeder that seeds roles, permissions, and users:

Contribution 🧑‍💻

We welcome contributions to this project. Please read our Contributing Guidelines before you start contributing.


All versions of laravel-role-permission with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/auth Version ^8.12|^9.0|^10.0|^11.0
illuminate/container Version ^8.12|^9.0|^10.0|^11.0
illuminate/contracts Version ^8.12|^9.0|^10.0|^11.0
illuminate/database Version ^8.12|^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package erag/laravel-role-permission contains the following files

Loading the files please wait ....