You can check that in your validation with the unique rule
https://stackoverflow.com/questions/50349775/laravel-unique-validation-on-multiple-columns
You can also put a unique constraint on the table.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello everyone, hope you are doing fine
in laravel 8 , am using the spatie package for managing roles and permissions , and it's doing great
how ever , i found that users can create roles with the same exact permissions (roles has many permissions) over and over again with different names
so my question is, how can i check if any existing role has the same exact given permissions by the user before creating a new one
@merabetabdelhalim count them to check perhaps? This should work
$ids = [2,3,7];
$roles = Role::withCount('permissions') - >whereHas('permissions', function ($query) use ($ids) {
$query->whereIn('id', $ids);
}, '=', count($ids))->get();
$final = $roles->filter(function ($item) use ($ids) {
return $item->permissions_count === count($ids);
});
Please or to participate in this conversation.