Git Product home page Git Product logo

laratrust's Introduction

Laratrust (Laravel Package)

Sponsor Latest Stable Version Total Downloads License tests

Version Compatibility

Laravel Laratrust
10.x, 11.X 8.x
9.x-10.x 7.x
8.x 6.x
7.x 6.x
6.x 6.x
5.6.x - 5.8.x 5.2
5.3.x - 5.5.x 5.1
5.0.x - 5.2.x 4.0.

Installation, Configuration and Usage

To install, configure and learn how to use Laratrust please go to the Documentation.

What does Laratrust support?

  • Multiple user models.
  • Multiple roles and permissions assignable to users.
  • Multiple permissions assignable to roles.
  • Roles and permissions verification.
  • Roles and permissions caching.
  • Events when roles and permissions are added, removed or synced.
  • Multiple roles and permissions can be added to users within teams.
  • Multiple guards for the middleware.
  • A simple administration panel for roles and permissions.
  • Laravel gates and policies.

License

Laratrust is open-sourced software licensed under the MIT license.

Contributing

Please report any issue you find in the issues page. Pull requests are more than welcome.

laratrust's People

Contributors

carusogabriel avatar coeuscc avatar denisdulici avatar dependabot[bot] avatar filippotoso avatar gdebrauwer avatar geosot avatar gregpeden avatar hazzazbinfaiz avatar jeffbeltran avatar kkszymanowski avatar laravel-shift avatar m1kfb avatar mathius17 avatar meeshalk avatar oele-dev avatar omalizadeh avatar ralbear avatar renatoagomes avatar romchik avatar santigarcor avatar sevannerse avatar sgarcia-leantech avatar stevevg avatar storyn26383 avatar sumityadav avatar supianidz avatar tomopongrac avatar wotta avatar zamcsaba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laratrust's Issues

blade directive not working

@santigarcor

The blade directive is showing as plain text and it is not working. I am facing this issue on product server, not at my local.

Can you please help me to register it.

Groups / Teams

Hi.

Ealier today I created an issue on the original entrust repo, regarding the possibility of adding groups to the package.

However i just noticed the concerns regarding the maintainer of the original repo, so I looked up forks and stumbled upon this. Even though I'm gonna make the pull request myself, I would very much prefer the code going into a maintained codebase.

(BTW I've done a lot of explanation of my problem on the original issue, so please check it out if you're unsure of what I mean by groups)

Personally I think many people would benifit for this feature, since It's very common for application to be based around groups (like slack).

Add `use LaratrustUserTrait` with a command call

Hi.

I'm currently working on package which:

  1. Reads PHP file
  2. Adds trait import above the class
  3. Adds use Trait at the top of the class definition

Are you interested in integrating it with your package to automatically add LaratrustUserTrait to App\User class(eg. with a command)? If so, I will put together a PR and post it within few days.

I can't install laratrust in laravel 5.3

hi
I can't install your laratrust in my fully working laravel 5.3
I follow your documentation for installation step by step
after commit basic configuration when I'm going to run this command:
php artisan vendor:publish
I've got this message:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Laratrust\LaratrustServiceProvider' not found

Postgres Error

I think, Laracast should be compartible with Postgres, because Laravel is compartible.

But I have this error:

[Illuminate\Database\QueryException]
SQLSTATE[42704]: Undefined object: 7 ERROR:  unrecognized configuration parameter "foreign_key_checks" (SQL: SET FOREIGN_KEY_CHECKS = 0)

[PDOException]
SQLSTATE[42704]: Undefined object: 7 ERROR:  unrecognized configuration parameter "foreign_key_checks"

Reason:
src/views/generators/seeder.blade.php

    /**
     * Truncates all the laratrust tables and the users table
     * @return  void
     */
    public function truncateLaratrustTables()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS = 0');
        DB::table('{{ config('laratrust.permission_role_table') }}')->truncate();
        DB::table('{{ config('laratrust.role_user_table') }}')->truncate();
        \{{ $user }}::truncate();
        \{{ $role }}::truncate();
        \{{ $permission }}::truncate();
        DB::statement('SET FOREIGN_KEY_CHECKS = 1');
    }

Here are some documentation comments on my recent install of Laratrust into a Laravel 5.2 project

-- Installation

Add a comma after
Laratrust\LaratrustServiceProvider::class
to match:
'Laratrust' => Laratrust\LaratrustFacade::class,

-- After Installation - configuration files

-- The following statement is not understandable. If I didn't have the original entrust documentation, I'd be totally lost:

Set the property values in the config/auth.php. These values will be used by laratrust to refer to the correct user model.

-- Somehow I wound up with two _laratrust_setup_tables.php

-- Documentation says:
** After the migration, four new tables will be present:**
In actuallity I got SIX new tables. In addition to the four mentioned I got groups and permission_user

-- Documentation says:
** Create a Role model inside app/models/Role.php using the following example: **
Is it not so that 1) Models go under app/ not app/model and 2) models should have initial caps filenames. If you really want them under app/models, the doc should instruct to create the models directory. Besides, once you do "composer dump-autoload" does it matter where they go?

-- Documentation says:
** Next, use the LaratrustUserTrait trait in your existing User model. For example:**

This seems to have been done automatically for me by an earlier step.

Enhorabuena Santi, has mejorado Entrust de manera significativa

Esta rama proporciona pequeñas mejoras pero en mucha cantidad, y lo mejor sin duda es la documentación, ojalá todos los proyectos estuviesen documentados así. Solo falta que salga adelante lo de los grupos, que es lo único que me has dejado hacer a mi en mi proyecto 😆

Couldn't create seeder.

php artisan laratrust:seeder

Couldn't create seeder.
Check the write permissions within the database/seeds directory.

php artisan db:seed --class=LaratrustSeeder

Creating Role SUPERADMINISTRATOR
Creating Permission to create for users
Creating Permission to read for users
Creating Permission to update for users
Creating Permission to delete for users
Creating Permission to create for acl
Creating Permission to read for acl
Creating Permission to update for acl
Creating Permission to delete for acl
Creating Permission to read for profile
Creating Permission to update for profile
Creating Role ADMINISTRATOR
Creating Permission to create for users
Creating Permission to read for users
Creating Permission to update for users
Creating Permission to delete for users
Creating Permission to read for profile
Creating Permission to update for profile
Creating Role PARTNER
Creating Permission to read for profile
Creating Permission to update for profile
Creating Permission to read for order_status
Creating Permission to update for order_status
Creating Role USER
Creating Permission to read for profile
Creating Permission to update for profile

Unable to install on Laravel 5.3

I get the following composer error:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: don't install santigarcor/laratrust 3.0.10
- Conclusion: don't install santigarcor/laratrust 3.0.9
- Conclusion: don't install santigarcor/laratrust 3.0.8
- Conclusion: don't install santigarcor/laratrust 3.0.7
- Conclusion: don't install santigarcor/laratrust 3.0.6
- Conclusion: don't install santigarcor/laratrust 3.0.5
- Conclusion: don't install santigarcor/laratrust 3.0.4
- Conclusion: don't install santigarcor/laratrust 3.0.3
- Conclusion: don't install santigarcor/laratrust 3.0.2
- Conclusion: don't install santigarcor/laratrust 3.0.1
- Conclusion: remove nikic/php-parser v3.0.2
- Installation request for santigarcor/laratrust 3.0.* -> satisfiable by santigarcor/laratrust[3.0.0, 3.0.1, 3.0.10, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.0.6, 3.0.7, 3.0.8, 3.0.9].
- Conclusion: don't install nikic/php-parser v3.0.2
- santigarcor/laratrust 3.0.0 requires kkszymanowski/traitor ^0.2.0 -> satisfiable by kkszymanowski/traitor[0.2.0, 0.2.1, 0.2.2].
- kkszymanowski/traitor 0.2.0 requires nikic/php-parser ^1.0 -> satisfiable by nikic/php-parser[v1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.2.0, v1.2.1, v1.2.2, v1.3.0, v1.4.0, v1.4.1].
- kkszymanowski/traitor 0.2.1 requires nikic/php-parser ^1.0 -> satisfiable by nikic/php-parser[v1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.2.0, v1.2.1, v1.2.2, v1.3.0, v1.4.0, v1.4.1].
- kkszymanowski/traitor 0.2.2 requires nikic/php-parser ^1.0|^2.0 -> satisfiable by nikic/php-parser[v1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.2.0, v1.2.1, v1.2.2, v1.3.0, v1.4.0, v1.4.1, v2.0.0, v2.0.1, v2.1.0, v2.1.1].
- Can only install one of: nikic/php-parser[v1.0.0, v3.0.2].
- Can only install one of: nikic/php-parser[v1.0.1, v3.0.2].
- Can only install one of: nikic/php-parser[v1.0.2, v3.0.2].
- Can only install one of: nikic/php-parser[v1.1.0, v3.0.2].
- Can only install one of: nikic/php-parser[v1.2.0, v3.0.2].
- Can only install one of: nikic/php-parser[v1.2.1, v3.0.2].
- Can only install one of: nikic/php-parser[v1.2.2, v3.0.2].
- Can only install one of: nikic/php-parser[v1.3.0, v3.0.2].
- Can only install one of: nikic/php-parser[v1.4.0, v3.0.2].
- Can only install one of: nikic/php-parser[v1.4.1, v3.0.2].
- Can only install one of: nikic/php-parser[v2.0.0, v3.0.2].
- Can only install one of: nikic/php-parser[v2.0.1, v3.0.2].
- Can only install one of: nikic/php-parser[v2.1.0, v3.0.2].
- Can only install one of: nikic/php-parser[v2.1.1, v3.0.2].
- Installation request for nikic/php-parser (locked at v3.0.2) -> satisfiable by nikic/php-parser[v3.0.2].

Installation failed, reverting ./composer.json to its original content.

It seems that php-parse is already installed in version 3.0.2 as a requirement of "classpreloader/classpreloader" which is a requirement of laravel itself.

What can i do?

What Cache Driver is Required?

Since this is a fork of zizaco's entrust, do you have to set the cache driver to something besides file? I know his had to use either memcached, redis or array to avoid getting that tagging error.

thanks!

Update cache by command

Hi @santigarcor ,

Is there any way to update laratrust cache using artisan command?

I have a project that have table structures like laratrust. But when I try to use laratrust, the permission cannot detected.

Can you give me a hint how to fix that?

Thanks

Role $model save() returns false after attaching/detaching roles in Laravel 5.3

When I change the permissions of a role with $role->attachPermission() or $role->detachPermission()and save the role, the role is updated in db but the save() method returns false(a.k.a. no actually model db change happened).

I think the reason for this is that in Laravel 5.3 the behaviour value of the save() method changed:

The Eloquent save method now returns false if the model has not been changed since the last time it was retrieved or saved.
https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0

Permit User if he is the Owner of a Record

Hello,
i have searched the code, but i can't find a proper way, through it's methods,
in order to permit a user edit a record if he owns it.

Is there any?

Thank in advance

Blade templates and user_role, potential issue?

Using blade helpers, unless I am miss understanding how this works, there seems to be an issue with using @Permission('insert-permission-here') when a user is only assigned to a role and the role is assigned permissions?

Does the role filter down permissions linked via the permission_role table without involving groups?

If I assign the permission direct to the user (using permission_user) then using @Permission allows access.
If I assign the user to a role (using role_user) and permission_user is empty, @Permission denys access.

Is this correct or is this a bug?

Migration doesn't seem to contain group table information as yet

Following setup instructions to the letter and seeing this error from MySQL:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'role_user.group_id' in 'field list' (SQL: select `roles`.*, `role_user`.`user_id` as `pivot_user_id`, `role_user`.`role_id` as `pivot_role_id`, `role_user`.`group_id` as `pivot_group_id` from `roles` inner join `role_user` on `roles`.`id` = `role_user`.`role_id` where `role_user`.`user_id` = 1)

Using 3.1.0-rc.1.

Attach Role to user when registering

Hello again,
I'm feeling kinda ashamed to ask for help again, but I'll just do.

I now got the seed running, so my db is filled with the information for the Permissions and Roles and then Permission-Role-Mapping.

This is how I seeded the data:

<?php

use Illuminate\Database\Seeder;

use App\Permission;
use App\Role;


class LaratrustSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $editProfile        = Permission::create(['name' => 'edit_profile', 'display_name' => 'Edit profile']);
        $searchProducts     = Permission::create(['name' => 'search_products', 'display_name' => 'Search for products']);
        $orderProduct       = Permission::create(['name' => 'order_product', 'display_name' => 'Order a product']);
        $manageCustomOrders = Permission::create(['name' => 'manage_custom_orders', 'display_name' => 'Manage custom orders']);
        $manageProducts     = Permission::create(['name' => 'manage_products', 'display_name' => 'Manage products']);
        $manageOrders    = Permission::create(['name' => 'manage_orders', 'display_name' => 'Manage orders from customers']);
        $adminManageOrders = Permission::create(['name' => 'admin_manage_orders', 'display_name' => 'Manage all orders as admin']);
        $adminManageProducts = Permission::create(['name' => 'admin_manage_products', 'display_name' => 'Manage all products as admin']);

        $admin  = Role::create(['name' => 'admin', 'display_name' => 'Administrator']);
        $buyer  = Role::create(['name' => 'buyer', 'display_name' => 'Buyer']);
        $seller = Role::create(['name' => 'seller', 'display_name' => 'Seller']);

        $admin->permissions()->attach([$editProfile->id, $searchProducts->id, $adminManageOrders->id, $adminManageProducts->id]);
        $buyer->permissions()->attach([$editProfile->id, $searchProducts->id, $orderProduct->id, $manageCustomOrders->id]);
        $seller->permissions()->attach([$editProfile->id, $manageProducts->id, $manageOrders->id]);
    }
}

Now, I tried to assign these Roles to the user, when he registers (I'm using the Auth from Laravel).
In my registration form, I already got 2 input radio buttons, to choose to register as seller or buyer.
So I just want to attach the "Laratrust" role to them while registering. So what I tried is (in RegisterController.php):

  protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'username' => $data['username'],
            'password' => bcrypt($data['password']),
            'role' => $data['role']
        ]);
        switch($data['role']){
            case 'Käufer':
                $user->attachRole($buyer); // also tried $buyer->id and combinations
                break;
            case 'Verkäufer':
                $user->attachRole($seller);
                break;
            default:
                $user->attachRole($buyer);
                break;
        }
        $user->save();
        return $user;
    }

But of course, it says $buyer is undefined... I also tried just "buyer" or roles()->attach("buyer") or several ways, but it doesn't know it. How can I do that? Do I have to import something? Do I have to get the roles, respectively the roles id out of the db? Whats the normal way to do this in here? Because in the docs, the example shows the situation, when you define the roels and then directly assign them, not when you saved them before (if I understood right).
Can you help me out?

facing issue while installing on linux - commands issue

Hi,

I am facing issue on linux while installing this package. After installation, it is giving me
Class name must be a valid object or a string error

I am not able to run the laratrust commands from console. Did i have to do some thing special on linux.

Short syntax route filter does not working in Laravel 5.3

If i use following short syntax
Laratrust::routeNeedsRole('/loginsuccess', 'customer', Redirect::to('/customer')); Laratrust::routeNeedsRole('/loginsuccess', 'admin', Redirect::to('/admin'))

laravel shows me error

BadMethodCallException in Macroable.php line 74: Method filter does not exist.

any suggestion?

User model relations in cache

Hello,
I set up caching with redis, and I was looking at what happens during my application life-cycle using redis-cli monitor.
When I login into my application, this command is run
"SETEX" "laravel:laratrust_roles_for_user_78" "3600" "O:39 [...]
which saves into cache a huge amont of data (i.e. my user with all its relations, that is really a lot of stuff).

Is there a way to stop laratrust doing so? I mean, I suppose that we are only interested in user's role, not all the relations that the user brings with himself...

If this can help, the same issue happened with entrust (I just switched to laratrust yesterday).

NotFoundHttpException even when access should be denied

I have a resource route, that represent a model, say customers, and access to all of the routes should be restricted to users that have a certain role. The route has the URI "customers/{customer}". As expected, access to existing customers is blocked by the role middleware.

But when entering an invalid route parameter the application returns a NotFoundHttpException, indicating that the parameter is resolved before the middleware even checks if the user is allowed to access that information. This way even an unauthorized person can figure out which route parameters are valid, and can determine how many customers are registered.

Also this prevents the standard 403 response from being sent out, since the NotFoundHttpException takes priority.

User wise redirect after Login

Hello,
I am new in Laravel. I am trying laratrust for role wise authentication. Can any one tell me, how to redirect user according to their role after login.
I.E:
Admin User
Redirect to : /admin

Employee User
Redirect to: /employee

Strange behaviour of permission

Hello.
I am really loving this package! I've been using this successfully for a while now. However, today I got a problem. I set up "admin" role with permission "manage-roles".
But $user->can('manage-roles') == false.
Moreover, $user->hasRole('admin') == true.
So I set up a little testing:
$role = \App\Role::where('name', 'admin')->first();
Finds my role - cool.
dump($role->permissions);
Through relations property I can see that "manage-roles" entry of Role model - cool again.
dump($role->hasPermission('manage-roles'));
I get false. I can't understand why. Any ideas?
Thank you!

Where to create roles and permissions?

Hello,

In your guide, you write

Let’s start by creating the following Roles and Permissions:

$owner = new Role();
$owner->name         = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description  = 'User is the owner of a given project'; // optional
$owner->save();

$admin = new Role();
$admin->name         = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description  = 'User is allowed to manage and edit other users'; // optional
$admin->save();

Where do I have to do this? I'm a bit confused about it... I made the two models for Role and Permission, but this is not the right place for it, right? Where else? Maybe this is too easy, I don't know, but I don't really get it..

Testing the 4.0.0-rc.1 version

Hi everybody,

i would like to ask everyone if you can test the new version, in order to check that the new groups integration is working fine and has all the needed interfaces and features to make it work easily.

Thanks!

LaratrustSeeder does not respect modified table names

Followed the instructions here:
http://laratrust.readthedocs.io/en/3.0/configuration/seeder.html

It looks like the trucateLaratrustTables() call is using hard-coded table names.

    // database/seeds/LaratrustSeeder.php
    /**
     * Truncates all the laratrust tables and the users table
     * @return    void
     */
    public function truncateLaratrustTables()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS = 0');
        DB::table('permission_role')->truncate();
        DB::table('role_user')->truncate();
        \App\User::truncate();
        \App\Role::truncate();
        \App\Permission::truncate();
        DB::statement('SET FOREIGN_KEY_CHECKS = 1');
    }

In my installation I've renamed all of the tables, so the code fails with the following errors:

[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.permission_role' doesn't exist (SQL: truncate permission_role)

[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.permission_role' doesn't exist

It looks like making the following change to truncateLaratrustTables() resolves the error:

    // database/seeds/LaratrustSeeder.php
    /**
     * Truncates all the laratrust tables and the users table
     * @return    void
     */
    public function truncateLaratrustTables()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS = 0');
        DB::table(config('laratrust.permission_role_table'))->truncate();
        DB::table(config('laratrust.role_user_table'))->truncate();
        \App\User::truncate();
        \App\Role::truncate();
        \App\Permission::truncate();
        DB::statement('SET FOREIGN_KEY_CHECKS = 1');
    }

Problems with installation

Hey,

I am trying to install laratrust and use it in a project.

What i have done is the following:

  1. added laratrust to the require part of my composer.son
    "require": { "php": ">=5.6.4", "laravel/framework": "5.3.*", "teepluss/theme": "dev-master", "santigarcor/laratrust": "3.0.*"
  2. I run composer update what managed to download laracast
  3. I added the provider and the alias part

Provider:

` /*
* Package Service Providers...
*/

    'Teepluss\Theme\ThemeServiceProvider',
    Laratrust\LaratrustServiceProvider::class,

`

Aliases:

'Lang' => Illuminate\Support\Facades\Lang::class, 'Laratrust' => Laratrust\LaratrustFacade::class, 'Log' => Illuminate\Support\Facades\Log::class,

  1. I wanted to run php artisan vendor:publish which happened not to generate a laratrust.php in my config directory
  2. When I tried to run php artisan laratrust:setup which wasn't execution with following error message:

[Symfony\Component\Console\Exception\CommandNotFoundException] There are no commands defined in the "laratrust" namespace.

I have redone the whole installing part twice to check that I didn't read over something. Any ideas how to solve this?

Integration testing

I have an idea for doing some integration tests.

Create a Laravel app, using Laratrust and write tests there.

What I mean is:

  1. Setup an sqlite database with all the needed scaffolding
  2. Fill it with several users, with different roles and permissions
  3. Write some routes and views
  4. Write simple tests for all of this like
Auth::loginUsingId(1);
$this->visit('/permission/1')
     ->see('You are authorized to see this');

Auth::loginUsingId(2);
$this->visit('/permission/1')
     ->see('You are not authorized to see this');

// or

$this->visit('/permission/1')
     ->assertRedirectedTo('/', ['message' => 'Unauthorized access']);

and so on.

This app will pull in santigarcor/laratrust: "master" so every time there is a change in Laratrust you would click "Restart Build" in Travis for this app to see if it all still works.

What do you think about this?
Do you have better ideas?

I also think it would be great for regression tests eg. user says "When I do this and that everything crashes" we would be able to reproduce this error, write tests to fail it, fix the error and see tests turn green(just like Jeffrey explains here)

Using Middleware; redirect instead of throw exception

Wouldn't it be nicer if we would use a redirect to a specifiable route instead of just calling abort(403). Or maybe make it optional?!

We could ad a config entry like

'middleware_handling' => 'abort',
'middleware_params' => '403',

and change abort(403) in Middleware to

call_user_func(config('laratrust.midleware_handling'), config('middleware_params));

=> just an idea!

Role relationship perms changed to permissions?

I was using Entrust previously but I was getting issues after updating to Laravel 5.2 and changing vendor files to fix the issue doesn't sit well with me.

Anyway back to point, I am getting an error "Call to undefined method Illuminate\Database\Query\Builder::perms()'" when calling $role->perms(). Has the relationship model name been changed to permissions? In the documents for Soft-Deleting, the example code still makes a reference to $role->perms()->sync([]) though. Please advice.

User-based Permissions

Currently Laratrust has Role-based Permissions, my proposal is to add User-based permissions.

A brief description taken from Cartalyst's Sentinel:
Give the user-based permissions a higher priority and will override role-based permissions. Any permissions granted/rejected on the user will always take precedence over any role-based permissions assigned.

An examples where this could be useful: disallowing a user to post on a forum or participate in a chat room.

Changing the user's role just for that isn't very practical I think.

I am new to this so I apologize in advance if this doesn't make any sense or I'm posting in the wrong section.

composer.json requirements for laravel 5.3.18

Hello,

in the "master" branch there are the following 3 requirements :

"illuminate/console": "~5.1.0",
"illuminate/support": "~5.1.0",
"illuminate/cache": "~5.1.0",

but the versions are 5.3 for those 3 components by now.
Could you please correct it in the composer.json file ?

Thank you !

[5.3] Blade Syntax Error

When using @Permission('order.create') in a Laravel 5.3-dev view I get the following error.

ErrorException
Parse error: syntax error, unexpected ''order.create'' (T_CONSTANT_ENCAPSED_STRING)

I need to use @Permission(('order.create')) in the view and the error is gone and permissions work fine. Might need a PR for this.

Does laratrust play well with Multi-Auth setup allowed in 5.2+ ?

I am thinking of moving from 5.1 LTS to 5.2 since I have a project that I want to separate my regular users (mainly admins) with Vendors/Suppliers stored in a 2nd table.

I wont be using groups or permissions on Suppliers but I am wondering if laratrust plays well in a Multi-Auth setup.

Anyone using laratrust in a Multi-Auth setup to share their experience ?

Guidelines for moving from zizaco/entrust

Hi there just found this fork of zizaco/entrust and really really happy about it since entrust is kind of dead atm.

Any guidelines of moving from entrust to laratrast? Or I should simply swap packages along with namespaces and get going? I am using "zizaco/entrust": "master@dev"

syntax error, unexpected end of file in Blade

@permission('manage-admins')
    This is visible to users with the given permissions. Gets translated to
    \Laratrust::can('manage-admins'). The @can directive is already taken by core
    laravel authorization package, hence the @permission directive instead
@endpermission

syntax error, unexpected end of file

Namespace idea

How about using Laratrust as the vendor namespace instead of Santigarcor\Laratrust.
For example Santigarcor\Laratrust\LaratrustRole would become simply Laratrust\LaratrustRole.

It's easier to remember and LaratrustFacade due to an alias is used without Santigarcor prefix so it would provide consistency.

What do you think?

Question about LaratrustUserTrait::can

UPDATE: Probably the same question for hasRole()

I was wondering, shouldn't $user->can([]) return true when user has no permissions?

Example:
We have some collection of Things. Every one of the Things requires one from a set of permissions to access. Some of them don't require any permissions to access.
When a User doesn't have any permissions, he should still access the Thing that requires no permissions.

With current algorithm, in previously mentioned case User is forbidden to do that, because we return $requireAll which is false.

Unable to install

composer complains with:

Problem 1
    - Conclusion: don't install santigarcor/laratrust 2.0.2
    - Conclusion: don't install santigarcor/laratrust 2.0.1
    - Conclusion: remove nikic/php-parser v2.1.0
    - Installation request for santigarcor/laratrust 2.0.* -> satisfiable by santigarcor/laratrust[2.0.0, 2.0.1, 2.0.2].
    - Conclusion: don't install nikic/php-parser v2.1.0
    - santigarcor/laratrust 2.0.0 requires kkszymanowski/traitor ^0.2.0 -> satisfiable by kkszymanowski/traitor[0.2.0, 0.2.1].
    - kkszymanowski/traitor 0.2.0 requires nikic/php-parser ^1.0 -> satisfiable by nikic/php-parser[v1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.2.0, v1.2.1, v1.2.2, v1.3.0, v1.4.0, v1.4.1].
    - kkszymanowski/traitor 0.2.1 requires nikic/php-parser ^1.0 -> satisfiable by nikic/php-parser[v1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.2.0, v1.2.1, v1.2.2, v1.3.0, v1.4.0, v1.4.1].
    - Can only install one of: nikic/php-parser[v1.2.1, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.2.2, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.3.0, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.4.0, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.4.1, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.0.0, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.0.1, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.0.2, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.1.0, v2.1.0].
    - Can only install one of: nikic/php-parser[v1.2.0, v2.1.0].
    - Installation request for nikic/php-parser (locked at v2.1.0) -> satisfiable by nikic/php-parser[v2.1.0].

Class name must be a valid object or a string..

hello..

am just use your package now.. and when i trying to
php artisan laratrust:migration
I got this error:
`[2016-08-11 14:10:25] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class name must be a valid object or a string in C:\xampp\htdocs\enngezshirt\vendor\santigarcor\laratrust\src\commands\MigrationCommand.php:109
Stack trace:
#0 C:\xampp\htdocs\enngezshirt\vendor\santigarcor\laratrust\src\commands\MigrationCommand.php(83): Laratrust\MigrationCommand->createMigration('roles', 'role_user', 'permissions', 'permission_role')
#1 [internal function]: Laratrust\MigrationCommand->fire()
#2 C:\xampp\htdocs\enngezshirt\vendor\laravel\framework\src\Illuminate\Container\Container.php(507): call_user_func_array(Array, Array)
#3 C:\xampp\htdocs\enngezshirt\vendor\laravel\framework\src\Illuminate\Console\Command.php(169): Illuminate\Container\Container->call(Array)
#4 C:\xampp\htdocs\enngezshirt\vendor\symfony\console\Command\Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 C:\xampp\htdocs\enngezshirt\vendor\laravel\framework\src\Illuminate\Console\Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 C:\xampp\htdocs\enngezshirt\vendor\symfony\console\Application.php(794): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 C:\xampp\htdocs\enngezshirt\vendor\symfony\console\Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Laratrust\MigrationCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 C:\xampp\htdocs\enngezshirt\vendor\symfony\console\Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 C:\xampp\htdocs\enngezshirt\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 C:\xampp\htdocs\enngezshirt\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 {main}

`
@santigarcor

blade directive change in Laravel 5.3 (still beta!)

I use the laravel 5.3-dev at the moment for a new project.
So this info is only for testers - no fix needed for a beta release of laravel!

blade directives does not longer give the "(" and ")" as $expression:

so it becomes:

<?php if (app('laratrust')->hasRole"root") : ?>

LaratrustServiceProvider.php:83

        // Call to Laratrust::hasRole
        $bladeCompiler->directive('role', function ($expression) {
            return "<?php if (app('laratrust')->hasRole{$expression}) : ?>";
        });

fix:

1: use always double "((" and "))" like "@ROLE(("root"))" (this fixes problems in other not laravel 5.3 ready libs too)

2: add the "(" and ")" in LaratrustServiceProvider.php (it's working in laravel 5.2 to, becomes double "(" and ")" but makes no problems)

i use "@ROLE(("root"))" in blade templates for now, because i think more libs will have this problems.

Lumen support

I've try install v3.0.6 on lumen 5.2 with no luck.

After adding this line in file: /bootstrap/app.php
$app->register(Laratrust\LaratrustServiceProvider::class);

I got a error:

[ErrorException]
  Argument 1 passed to Laratrust\LaratrustServiceProvider::boot() must be an instance of Illuminate\View\Factory, none given, called in /usr/local/www/apache24/data/cartrade/backend/vendor/
  laravel/lumen-framework/src/Application.php on line 173 and defined

I also try to instal dev branch but have composer error

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for santigarcor/laratrust dev-master -> satisfiable by santigarcor/laratrust[dev-master].
    - Conclusion: remove illuminate/cache v5.2.45
    - Conclusion: don't install illuminate/cache v5.2.45
    - santigarcor/laratrust dev-master requires illuminate/cache ~5.1.0 -> satisfiable by illuminate/cache[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8].
    - Can only install one of: illuminate/cache[v5.1.1, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.13, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.16, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.2, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.20, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.22, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.25, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.28, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.30, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.31, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.41, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.6, v5.2.45].
    - Can only install one of: illuminate/cache[v5.1.8, v5.2.45].
    - Installation request for illuminate/cache (locked at v5.2.45, required as ~5.1) -> satisfiable by illuminate/cache[v5.2.45].

I'm pretty noob in Laravel family btw.

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.