Download the PHP package luongtran/laravel-mongodb-permission-spatie without Composer

On this page you can find all versions of the php package luongtran/laravel-mongodb-permission-spatie. 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-mongodb-permission-spatie

Associate users with roles and permissions (Mongodb/Moloquent)

This package allows to save permissions and roles in a database. It is built extend from Spatie Laravel Permission

Once installed you can do stuff like this:

You can test if a user has a permission with Laravel's default can-function.

Install

You can install the package via composer:

This service provider must be installed. And Spatie provider too.

You can publish the config-file with:

This is the contents of the published config file:

Adjust the table_names config above for support mongodb many to many relationships (using EmbedsMany)

Usage

First add the Spatie\Permission\Traits\HasRoles-trait to your User model.

This package allows for users to be associated with roles. Permissions can be associated with roles. A Role and a Permission are regular Eloquent-models. They can have a name and can be created like this:

The HasRoles adds eloquent relationships to your models, which can be accessed directly or used as a base query.

Using permissions

A permission can be given to a user:

A permission can be revoked from a user:

You can test if a user has a permission:

Saved permissions will be registered with the Illuminate\Auth\Access\Gate-class. So you can test if a user has a permission with Laravel's default can-function.

Using roles and permissions

A role can be assigned to a user:

A role can be removed from a user:

Roles can also be synced :

You can determine if a user has a certain role:

You can also determine if a user has any of a given list of roles:

You can also determine if a user has all of a given list of roles:

The assignRole, hasRole, hasAnyRole, hasAllRoles and removeRole-functions can accept a string, a Spatie\Permission\Models\Role-object or an \Illuminate\Support\Collection-object.

A permission can be given to a role:

You can determine if a role has a certain permission:

A permission can be revoked from a role:

The givePermissionTo and revokePermissionTo-functions can accept a string or a Spatie\Permission\Models\Permission-object.

Saved permission and roles are also registered with the Illuminate\Auth\Access\Gate-class.

Using blade directives

This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.

You can use Laravel's native @can directive to check if a user has a certain permission.

Using a middleware

The package doesn't contain a middleware to check permissions but it's very trivial to add this yourself.

This will create a RoleMiddleware for you, where you can handle your role and permissions check.

Don't forget to add the route middleware to your Kernel:

Now you can protect your routes using the middleware you just set up:

Extending

If you need to extend or replace the existing Role or Permission models you just need to keep the following things in mind:

Unit Test

Soon.


All versions of laravel-mongodb-permission-spatie with dependencies

PHP Build Version
Package Version
Requires illuminate/container Version ^10.0
spatie/laravel-permission Version ^5.5
luongtran/moloquent Version ^1.0.0
jenssegers/mongodb Version 4.0.0-rc1
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 luongtran/laravel-mongodb-permission-spatie contains the following files

Loading the files please wait ....