Giter Site home page Giter Site logo

wovosoft / laravel-permissions Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 1.53 MB

Front-End Implementation of spatie/laravel-permission

Home Page: https://github.com/spatie/laravel-permission

License: MIT License

PHP 32.67% JavaScript 6.90% Vue 60.43%
laravel vuejs roles-management permissions roles-permission-management spatie-laravel-permission

laravel-permissions's Introduction

Wovosoft Software Development Compnay

Laravel Role & Permissions Front-End Implementation using spatie/laravel-permission

Latest Stable Version Total Downloads Latest Unstable Version License

Package description

The package is a Front-End Implementationf of the spatie/laravel-permission package. The spatie/laravel-permission is an awesome package for managing Roles & Permissionf for Laravel applications out of the box. But currently it doesn't have the front-end to easily deploy in your application.

This package comes to solve this problem. The package implements almost every features provided by spatie/laravel-permission.

Features

  • Vue Components for each possible features .
  • Components are reusable. So, the default layout can be modified according to the needs of your application.
  • Currently the front-end uses Bootstrap-Vue. But you can easily change it's layout.
  • The front-end vue components are packaged as an npm package. You can use it as a module for you bundlers eg. Webpack,
  • Check the main spatie/laravel-permission for more details.

Installation

Install via composer

composer require wovosoft/laravel-permissions

Publish Configuration File

  1. Publish the configuration file.
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="config"
  1. Publish the Vue Components. The Published components will be copied to resources/laravel-permissions/permissions folder. You need to add the Main.vue component to your app.js
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="resources"
  1. Publish the Migrations
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="migrations"
  1. Publish the Seeds
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="seeds"

Configuration

  1. In App\User.php model add the HasRoles.php Trait.
//other imports goes here
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
    // other codes goes here
}
  1. Now Run
php artisan migrate
  1. Go to config/laravel-permissions.php . Add Default Permissions and Roles.
<?php

return [
    "route_name_prefix" => "Wovosoft",
    "route_url_prefix" => "backend",
    "middleware" => ["web", "auth"],
    "users_table" => "users",                //Default Laravel Generated Name
    "roles_table" => config("permission.table_names.roles"),                //comes from spatie config file.
    "permissions_table" => config("permission.table_names.permissions"),    //comes from spatie config file
    "default_permissions" => [
        [
            "name" => "add user",
            "description" => "Can Add User"
        ],
        [
            "name" => "edit user",
            "description" => "Can Edit User"
        ],
        [
            "name" => "delete user",
            "description" => "Can Delete User"
        ]
    ],
    "default_roles" => [
        [
            "name" => "Super Admin",
            "description" => "Super Admin Manages Everything"
        ],
        [
            "name" => "User",
            "description" => "User Role"
        ],
        [
            "name" => "Customer",
            "description" => "Customer Role"
        ]
    ]
];
  1. The package adds the routes automatically prefixed by backend, so your other routes should't be prefixed by backend. But you can change it in config/laravel-permissions.php config file. To check the registered routes, run in your terminal from project the root,
php artisan route:list
  1. The gates are automatically registered during boot-up by spatie/laravel-permission

Usage

  1. So, according to config/laravel-permissions.php (#3) you can perform user abilities as follows:
if(auth()->can('permission')){
  echo "Auth user is allowed to perform this operation";
}
if(App\User::find(1)->can('permission')){
  echo "Auth user is allowed to perform this operation";
}
$role = Wovosoft\LaravelPermissions\Models\Roles::find(1);
if($role->hasAbility('permission')){
  echo "The Role with ID 1 is allowed to perform this operation";
}
  1. Check the main spatie/laravel-permission for more details.

Note

Please keep in mind, the default Role and Permission models provided by spatie/laravel-permission are extended in the package. That's why rather than using Spatie\Permission\Models\Role for Role and Spatie\Permission\Models\Permission please use Wovosoft\LaravelPermissions\Models\Roles for Role and Wovosoft\LaravelPermissions\Models\Permissions for Permission respectively.

Example Project

Click here to check the demo project https://github.com/wovosoft/laravel-permissions-example

Security

If you discover any security related issues, please email [email protected] or create issue in the Github Repository.

Credits

This package is bootstrapped with the help of wovosoft/crud.

laravel-permissions's People

Contributors

dependabot[bot] avatar narayanadhikary avatar wovosoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

m0rtem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.