Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Integrity constraint violation #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Ntrust/Traits/NtrustRoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function savePermissions($inputPermissions)
*
* @return void
*/
public function attachPermission($permission)
public function attachPermission($permission, $duplicate = TRUE)
{
if (is_object($permission)) {
$permission = $permission->getKey();
Expand All @@ -157,7 +157,13 @@ public function attachPermission($permission)
$permission = $permission['id'];
}

$this->perms()->attach($permission);
if ($duplicate === TRUE) {
$this->perms()->attach($permission);
} else {
if (!$this->perms->contains($permission)) {
$this->perms()->attach($permission);
}
}
}

/**
Expand Down Expand Up @@ -185,10 +191,10 @@ public function detachPermission($permission)
*
* @return void
*/
public function attachPermissions($permissions)
public function attachPermissions($permissions, $duplicate = TRUE)
{
foreach ($permissions as $permission) {
$this->attachPermission($permission);
$this->attachPermission($permission, $duplicate);
}
}

Expand Down