Download the PHP package mimachh/guardians without Composer

On this page you can find all versions of the php package mimachh/guardians. 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 guardians

Mimachh/Guardians

Mimachh/Guardians is a Laravel package designed to simplify the management of user roles within your application. It provides an easy-to-use interface for associating roles with users, including methods for adding, removing, updating roles, and checking user roles. This package leverages a many-to-many relationship between users and roles to offer flexibility and control over user permissions.

Features

Installation

Install the package via Composer:

Publish the package's configuration file:

This will publish the configuration file to config/guardians.php.

Run the migrations:

This will create the necessary tables for roles and the pivot table role_user.

Register the Service Provider:

Add the service provider to the providers array in your config/app.php:

Configuration

The configuration file config/guardians.php includes:

Usage

Use the trait

First you will need to add the trait HasRoles to the user model.

Seed the roles

You can seed the default roles using :

Defining the Relationships

Ensure that your User and Role models define the many-to-many relationship:

User Model:

By default the relation $user->roles() is already loaded. But you can override it, if you need to.

Role Model:

Relation is many to many, and the Role Model is already attach to user model.

Assigning Roles

Attach a role to a user:

Attach several roles to a user:

Detach a role from a user:

Check user role:

Using Observers

The package includes an observer to automatically assign default roles to new users:

Ensure the observer is registered in the GuardiansServiceProvider:

Middleware

The package gives you a middleware to check the users's roles.

Register the middleware

Give the middleware an alias :

Use the middleware

Use it as you use any middleware, but ensure you pass the slug of the authorized role.

Testing

To test the package, you can create a new user and verify if the roles are attached correctly:

Roadmap

Incoming :

Contributing

If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub.

License This package is licensed under the MIT License. See the LICENSE file for more details.


All versions of guardians with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^11.9
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 mimachh/guardians contains the following files

Loading the files please wait ....