laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

Custom primary key in users table error

Open pmtechnik opened this issue 8 years ago • 2 comments

If you change your primary key on users table from 'id' to a custom one like 'user_id' you get wrong user roles. The cacheentry for user roles will be overwritten and a user is able to access resources he's not allowed to.

How to fix

Change:

$this_roles = \Cache::remember(
	'acl.getRolesById_'.$this->id,
	config('acl.cacheMinutes'),
	function () {
		return $this->roles;
	}
);

To:

$this_roles = \Cache::remember(
	'acl.getRolesById_'.$this->getKey(),
	config('acl.cacheMinutes'),
	function () {
		return $this->roles;
	}
);

The bug is in line 40 of HasRole.php file

pmtechnik avatar Dec 15 '16 11:12 pmtechnik

Rel #171

pmtechnik avatar Dec 15 '16 11:12 pmtechnik

@profile-media can you please post a PR?

kodeine avatar Jan 03 '17 19:01 kodeine