laratrust
laratrust copied to clipboard
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry when trying to attach new permissions
- Laravel Version: 8.40
- Laratrust Version: 6.3
When i try to update permissions for a specific user (it's an App\Models\Organization
infact), i'm getting the following error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-8-App\Models\Organization' for key 'permission_admin.PRIMARY' (SQL: insert into
permission_admin
(admin_id
,permission_id
,user_type
) values (1, 8, App\Models\Organization))
The code that does that looks like the following:
$organization = Organization::withTrashed()->find($organization_id);
$organization->syncPermissions($data["permissions"]);
Where $data["permissions"]
contains IDs of permissions to add.
Strangely, the operation succeeds and the permissions are persisted, but the above error shows regardless.
I've did another try, i've detached the permissions and then re-attached them again, but the same error keeps on showing.