Giter Club home page Giter Club logo

laravel-permission's People

Contributors

adrianmrn avatar alexvanderbist avatar angeljqv avatar artissant avatar barryatswisnl avatar cesargb avatar ctf0 avatar dependabot[bot] avatar drbyte avatar erikn69 avatar freekmurze avatar fullstackfool avatar github-actions[bot] avatar josepostiga avatar juliomotol avatar juvpengele avatar kylekatarnls avatar lloople avatar lloricode avatar lowerends avatar mattdfloyd avatar matthewgoslett avatar musapinar avatar nielsvanpach avatar olivernybroe avatar patinthehat avatar sebastiandedeyne avatar sergejostir avatar springleng avatar tomlankhorst 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  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

laravel-permission's Issues

Check if a role has a permission

Is it possible to check if a role has a specific permission?

For example, I want to display all roles and all its permissions. What I'm doing now is just:

        foreach (Role::all() as $role) {
           $permissions = $role->permissions);
           // Etc..
        }

But I'm looking for something like:

        foreach (Role::all() as $role) {
            dd($role->can('view-user')); // Example
        }

Please Add Additional Method...

I love this package!!! We use it all through out our sites. Having said that, there is one functionality that I haven't been able to find but desperately needed... so I added it to my files but would greatly appreciate if any new releases included this in the HasPermissions.php file...

/**
 * Determine if the role has (one of) the given permission(s).
 *
 * @param string|array|Permission|\Illuminate\Support\Collection $roles
 *
 * @return bool
 */
public function hasPermission($permissions)
{
    if (is_string($permissions)) {
        return $this->permissions->contains('name', $permissions);
    }

    if ($permissions instanceof Permission) {
        return $this->permissions->contains('id', $permissions->id);
    }

    if (is_array($permissions)) {
        foreach ($permissions as $permission) {
            if ($this->hasPermission($permission)) {
                return true;
            }
        }

        return false;
    }

    return (bool) $permissions->intersect($this->permissions)->count();
}

PS. If this functionality exists and I just haven't found it please let me know so that I can use this better.

Cheers,
Jay

can not working

Hi,
I am running Laravel 5.2.25 and i succesfully created roles and assigned permission to those roles.
(role "admin" has permission "create-user").

Calling "hasPermissionTo" and "hasRole" on a user is working fine. Calling $user-can('create-user') is simply doing nothing. No Exception. No return.

any ideas?

Allow extension of Role and Permission

Hi

I've ran into the case that I need to be able to assign a description to the Permission model.
Normally, one would extend the Permission class and proceed, however this won't work with this package since both Role and Permission classes are quite a lot hard-coded using class imports.

Some suggestions:

  • use the IoC to bind an Eloquent model to Role and Permission to allow developers to override when necessary.
  • use a config value like Laravel's built-in auth.model

Do you Have a More Detailed way of Using this?

It would be really best if you can provide an example usage of your package
A wiki perhaps?
Ive been able to require it in the package and migrate
dont know if i will create a Model App\Permission , App\Roles
to set the database so far i see it is all in the vendor package
Dont really wanna messed up your code
by adding protected $table = 'roles'; etc.
Or can it be extended , or implements
inside controller or model.
Sorry hope you can really give a detailed set up and usage
๐Ÿ‘

Names are not unique

I'm wondering if there's a design rationale for the "name" columns to be non-unique? It doesn't really seem like you'd want multiple permissions & roles with the same name.

Class CreatePermissionTables not found

When editing the migration file to add some more columns in the table and try to migrate it it says: "Class CreatePermissionTables" not found. Do you have any hint for that?

Feature: add blade directives to check if user has certain role

It would be useful to have a blade directive that checks if a user has all or any of a given list (array) of roles. The syntax could be like this:

@has(['role_1', 'role_2', 'role_3'])
<some html/php here>
@else
<some other html/php here>
@endhas

What are your thoughts on this?

Error - Column not found

This error occurred when executing the command $role->givePermissionTo($permission->name);

PDOException in Connection.php line 390: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'role_id' in 'field list'

in Connection.php line 390
at PDO->prepare('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)') in Connection.php line 390
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1')) in Connection.php line 648
at Connection->runQueryCallback('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1'), object(Closure)) in Connection.php line 611
at Connection->run('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1'), object(Closure)) in Connection.php line 391
at Connection->statement('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1')) in Connection.php line 347
at Connection->insert('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1')) in Builder.php line 1805
at Builder->insert(array(array('role_id' => '1', 'permission_id' => '1'))) in BelongsToMany.php line 898
at BelongsToMany->attach('1', array(), true) in BelongsToMany.php line 558
at BelongsToMany->save(object(Permission)) in HasPermissions.php line 18
at Role->givePermissionTo('crear usuarios') in AuxpermisosController.php line 65
at AuxpermisosController->store(object(Request))
at call_user_func_array(array(object(AuxpermisosController), 'store'), array(object(Request))) in Controller.php line 256
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuxpermisosController), object(Route), 'store') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(AuxpermisosController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\AuxpermisosController', 'store') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

QueryException in Connection.php line 655: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'role_id' in 'field list' (SQL: insert into user_has_permissions (permission_id, role_id) values (1, 1))

in Connection.php line 655
at Connection->runQueryCallback('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1'), object(Closure)) in Connection.php line 611
at Connection->run('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1'), object(Closure)) in Connection.php line 391
at Connection->statement('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1')) in Connection.php line 347
at Connection->insert('insert into `user_has_permissions` (`permission_id`, `role_id`) values (?, ?)', array('1', '1')) in Builder.php line 1805
at Builder->insert(array(array('role_id' => '1', 'permission_id' => '1'))) in BelongsToMany.php line 898
at BelongsToMany->attach('1', array(), true) in BelongsToMany.php line 558
at BelongsToMany->save(object(Permission)) in HasPermissions.php line 18
at Role->givePermissionTo('crear usuarios') in AuxpermisosController.php line 65
at AuxpermisosController->store(object(Request))
at call_user_func_array(array(object(AuxpermisosController), 'store'), array(object(Request))) in Controller.php line 256
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuxpermisosController), object(Route), 'store') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(AuxpermisosController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\AuxpermisosController', 'store') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

Teams

Hello
nice package. would it be possible to add a "Teams" or "Workspaces" a la spark on top of roles ?
For my saas project i would need a user-teams role definition so that I can have administrators, team administrators and members roles for each team. Permissions would be declared one time only like read, write, updated, delete, etc ... and would be reusable across roles. So one user could have many teams and in each team it would have different roles, connected with different permissions.
I'm asking instead of doing because i'm not sure how to figure it out.
have nice day
Francois

Register Blade Extention

First of all, excellent work!
Is there an easy way to add "haspermition" on registerBladeExtensions without messing up with this extension?

This would be useful no?

Cheers

how to use middleware role in route?

can i use role in route?
i try to use
Route::group(['middleware' => 'role:admin'], function () { Route::get('/admin', 'adminController@view'); });

but im gettin error

Class hasRole does not exist

Global Scope for Models of Various Roles

I want to make models for various roles that I make. So E.g., I'd be making a role called admin, and then for the Admin model, so that it'd be really easy to do things like Admin::all and so on.

I think that it can be done with Global Scopes.

Test (THIS WORKS)

$role = Role::where('name', "admin")->first();
User::whereHas('roles', function($query) use ($role){
            $query->where('roles.id', $role->id);
        })->get());

But this does not work.

Admin.php

class Admin extends Model
{
    use HasRoles;

    protected $role = "admin";

    protected $table = "users";

    public static function boot()
    {
        static::addGlobalScope(new AdminScope());
    }
}

AdminScope.php

public function apply(Builder $builder, Model $model)
    {
        $role = Role::where('name', "admin")->first();
        return $builder->whereHas('roles', function($query) use ($role){
            $query->where('roles.id', $role->id);
        });
    }

I get

QueryException in Connection.php line 651:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_has_roles.admin_id' in 'where clause' (SQL: select * from `users` where exists (select * from `roles` inner join `user_has_roles` on `roles`.`id` = `user_has_roles`.`role_id` where `user_has_roles`.`admin_id` = `users`.`id` and `roles`.`id` = 2))

Let me know if you need any other code. Thanks!

Is there a $role->hasPermissionTo ?

Thanks for sharing this... it's awesome. I need to obtain a list of permissions granted to a role. It appears that the hasPermissionTo method is for the user model only. Is there a means that I've overlooked to get a list of permissions granted to a role? At the moment, I'm getting by with:

in_array($permission->name, $role->permissions->pluck('name')->all())

Feature: hasAnyRole and hasAllRoles

It would be useful to have methods to check whether a user has any of a list of roles or whether a user has all of a list of roles.

If you agree with this, I can create a PR to add these methods.

Add hasPermission Blade directive

I guess this would be really usefull.

Lets say we have 3 rolls: admin, editiors, and readers.

And we have the permission: create posts. This one is given to admins and editors.

Now i would be able to show the create post button only for admins and editors with something like

@hasPermission('create posts')

Think that would be really helpful for a future release.

Regards
Michael

Multi auth

Hi, quick and simple question - it doesn't seem that it supports multi auth at the moment, I was wondering whether you are going to add support for it?

Struggling with @can

I have been trying to get @can to work for the past hour..

I have a permission setup for the role "President" with the permission "full-access". All have been assigned and my test user has been assigned the role of president.

When I do

@can('full-access')
<p>See This</p>
@endcan

I can't actually see that. Am I doing something wrong in this setup?

Wildcard for @can

Is it possible to have a wildcard for @can. Example. I have 4 permissions: person.view, person.update, person.delete, person.create. I want to use @can('person.*') to see if that user has any of the permissions listed?

Use hasPermissionTo in a closure

Not sure if this is a bug or if it's just me.

I would like to get all the users which have permission to 'write_post'.

        $users = User::where(function ($q) {
            $q->hasPermissionTo('write_post');
        })->get();

this fails with a BadMethodCallException thrown with message "Call to undefined method Illuminate\Database\Query\Builder::hasPermissionTo()"

Config file for setting table names

I think it's likely pretty common that a lot of us already have tables (from some other 3rd party acl) to do most of what this migrates. In interest of keeping db changes to a minimum, it'd be ideal for something like this

'tables' => [
    'permissions' => env('PERMISSIONS_TABLE','permissions'),
    'user_has_permissions' => env('USER_HAS_PERMISSIONS_TABLE','user_has_permissions'),
]

and so on with the rest of the tables.

Short issue, I have every table you're creating already, just named differently

forgetCachedPermissions() error

$role->givePermissionTo('edit');

Call to undefined method Illuminate\Database\Query\Builder::forgetCachedPermissions() error

HasPermissions.php file

public function givePermissionTo($permission)
{
$this->permissions()->save($this->getStoredPermission($permission));

    $this->forgetCachedPermissions();

    return $this;
}

It does not have this function forgetCachedPermissions()

Permissons and roles nicename

Great package! Upon initial spectation of the readme, doesnt seem to have a "nice name" attribute for roles and permissions.

Say a role is "editor" but on the Frontend you would like it to say "Site Editor".

Slugs

Also, If you made it so that we have slugs that would be awesome! I have found a few situations where I've been using ajax requests with these and slugs are mandatory for me. Not a massive pain to convert these to slugs and then back out of slug every time but, it's an extra step that could be quite automated.

Thanks again for the awesome package!

Class 'Role' not found

Hi,
I want to use @hasanyrole(Role::all()) in my Blade Template, but then i see error:
FatalErrorException in 9ab5bebbf6ae5ee24e88699faa66ec40 line 8: Class 'Role' not found

My template:

@section('htmlBody')
...
            @hasanyrole(Role::all())
                I have one or more of these roles!
            @else
                I have none of these roles...
            @endhasanyrole
...
@endsection

My Controller:

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Models\Role;


class clientArea extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function index(){
        $user = Auth::user();
        var_dump($user->hasAnyRole(Role::all()));

        return view('page.clientArea.index');
    }
}

In config\app.php:

'providers' => [
...
Spatie\Permission\PermissionServiceProvider::class,
...

Whats wrong?

Greetings
// sorry for my english

Authentication drivers & Naming convention of pivot tables

Since Laravel 5.2 has already supported Mupltiple Authentication, configurations like User Permissions Table (user_has_permissions) and User Roles Table (user_has_roles) should be attached to drives (array? maybe). Creating a branch for Laravel 5.2.* and higher is a great idea, I think.

Moreover, I think we should keep the naming convention of pivot tables of default configurations between these entities:
User - Permission table : permission_user
User - Role table: role_user
Permission - Role table: permission_role

Migration nothing to publish

Having problem with migration after installation:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"                                                                       
Nothing to publish for tag [migrations]

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"                                                                           
Nothing to publish for tag [config]

Laravel 5.2

Model not found

I'm facing a issue since this morning i get this error.

FatalErrorException in Model.php line 986: Class 'App\Role' not found

in my controller i added

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\User;
use Spatie\Permission\Models\Role as Role;
use Spatie\Permission\Models\Permission as Permission;

in my view

@can('manage_departments')
test
@endcan

Do you have any suggestions?

Seed Error

I have a seeder which truncates the Users table, but when I run artisan db:seed, I get this error message:

[Illuminate\Database\QueryException] 
SQLSTATE[42000]: Syntax error or access violation:
1701 Cannot truncate a table referenced in a foreign key constraint (`mydatabasename`.`user_has_permissions`, CONSTRAINT `user_has_permissions_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `mydatabasename`.`users` (`id`)) (SQL: truncate `users`)

I've managed to get around it by disabling and reenabling foreign_key_checks around the truncate method.

DB::statement('SET FOREIGN_KEY_CHECKS = 0');
DB::table('users')->truncate();
DB::statement('SET FOREIGN_KEY_CHECKS = 1');

Is there better way of addressing this issue?

Error on migrate:refresh

[Symfony\Component\Debug\Exception\FatalThrowableError] Fatal error: Class 'CreatePermissionTables' not found

Getting following above error on migrate refresh.

Just a suggestion for the Readme - Show Documentation for $user->roles

I'm using this packaged and it's very helpful, so thank you! It's the right balance of simple, yet fully functional. You've done great work.

I just have a minor suggestion to put on your README:

It doesn't say anywhere that you can directly access the associated roles and permissions for a user. For example, it would be nice for people to know that you can loop through all of a user's roles by doing something like this:

`foreach ($user->roles as $role)
{

}
`

I found this useful while creating an administration page with a list of all the users and their role(s).

spatie permission & authorize

If I spatie / laravel-permission and spatie / laravel-authorize install, I can not authorize use.

I get an error message in route.php. The normal Routes will no longer work. What am I doing wrong?

BadMethodCallException

Hi, I'm very begginer with Laravel. I try to use your awesome package.
I found error when running php artisan db:seed

[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::assignRole()

Here my UserTableSeeder:

'admin']); ``` $password = 1234; // ---------- Administrator $user = User::create([ 'name' => 'Administrator', 'email' => '[email protected]', 'password' => $password, ]); $user->assignRole($adminRole); ``` or same $user->assignRole('admin'); Could you explain to me, how to make usertableseeder? Thanks

Test User has more than one roles ?

How to test if user has one or more roles ?
Example:
There is 3 roles: admin, support, staff
User A is assigned for roles admin

If I want to know if user A has roles admin or staff.

Trying to use hasAnyRoles but no luck

Is this bug ?

When hasAnyRole('admin','staff') will return true
When hasAnyRole('staff','admin') will return false

Thanks

Problem with migrate

Hi Author.
I get error when do migrate.

These tables was created:

Please help check!

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.