I am developing a laravel user management system for my project that allows admins to edit a selected user that is registered on the website. The edit button opens up a modal form with the users information, which includes checkboxes for specific website permissions.
I am passing the permission info via data parameters and the permission checkboxes are then set to "checked" if the role name is included in the array of roles. Everything works as expected with single permissions, but as soon as I view a user with multiple permissions, the checkboxes remain checked for every user until the page is refreshed.
My code is as follows:
<a href="#" class="btn btn-edit" data-toggle="modal" data-target="#editModal" data-username="{{ $user->username }}" data-permissions="{{ $user->roles->pluck('name') }}" id="editUser">Edit</a>
sdfsdfsdf
<script type="text/javascript">
$(document).on('click', '#editUser', function() {
$('#edit-username').val($(this).data('username'));
var userPerms = $(this).data('permissions');
if (userPerms.includes('Admin'))
{
document.getElementById("edit-admin_perm").checked = true;
}
if (userPerms.includes('Captain'))
{
document.getElementById("edit-captain_perm").checked = true;
}
});
</script>
I'm not sure if there is way to "clear" the data on each button click to open the modal, or if there is another way to go about it. But after nearly an hour of searches, I have come up empty handed.
Any help would be much appreciated!