Replies: 4 comments
-
with 4.2 was it working? laravel-permission/tests/WildcardHasPermissionsTest.php Lines 13 to 30 in 78eaa5e I tried on 4.2 and User::permission('a.b.c')->get() nothing returns toomaybe $user->hasPermissionTo('a.b.c') instead of User::permission('a.b.c')->get()
|
Beta Was this translation helpful? Give feedback.
-
I made a test and /** @test */
public function it_can_check_wildcard_permission2()
{
app('config')->set('permission.enable_wildcard_permission', true);
$user1 = User::create(['email' => '[email protected]']);
$role = Role::create(['name' => 'RoleWild']);
$permission1 = Permission::create(['name' => 'a.b.c']);
$permission2 = Permission::create(['name' => 'a.*']);
$permission3 = Permission::create(['name' => 'a.b.*']);
//via direct permission
$user1->givePermissionTo($permission2);
$this->assertTrue($user1->hasPermissionTo('a.*'));
$this->assertTrue($user1->hasPermissionTo('a.b.*'));
$this->assertTrue($user1->hasPermissionTo('a.b.c'));
$this->assertSame([], User::permission('a.b.c')->get()->toArray());
// revoke direct permission
$user1->revokePermissionTo($permission2);
$this->assertFalse($user1->hasPermissionTo('a.*'));
$this->assertFalse($user1->hasPermissionTo('a.b.c'));
//via role
$role->givePermissionTo($permission2);
$user1->assignRole($role);
$this->assertTrue($user1->hasPermissionTo('a.*'));
$this->assertTrue($user1->hasPermissionTo('a.b.*'));
$this->assertTrue($user1->hasPermissionTo('a.b.c'));
$this->assertSame([], User::permission('a.b.c')->get()->toArray());
// with 'a.*' i get a result user
$this->assertSame([['id' => 2, 'email' => '[email protected]', 'deleted_at' => null]], User::permission('a.*')->get()->toArray());
// revoke role
$user1->removeRole($role);
$this->assertFalse($user1->hasPermissionTo('a.*'));
$this->assertFalse($user1->hasPermissionTo('a.b.c'));
} |
Beta Was this translation helpful? Give feedback.
-
Maybe laravel-permission/tests/HasPermissionsTest.php Lines 191 to 200 in 5b3ea6b |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hello and thanks for the great package.
I have a user which has
a.*
permission assigned via role (That is I have a role with permissiona.*
which that user has the role).But when I do the following query:
User::permission('a.b.c')->get()
nothing returns!
I have all set of
a.*
,a.b.*
, a.b.c` created already!I am using ver 4.3.0 as composer.lock says. (I just updated it from 4.2), PHP 8, Mysql 8 and Win10 (using apache via xampp)
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions