Currently, I'm in the process of building a Laravel user management system for a project. This system will allow admins to edit any selected user who is registered on our website. Upon clicking the edit button, a modal form containing the user's details will appear, along with checkboxes for specific website permissions.
To pass the permission information, I am utilizing data parameters. The checkboxes are then marked as "checked" if the role name is found within the array of roles. However, I've encountered an issue where when viewing a user with multiple permissions, the checkboxes remain checked until the page is refreshed.
The code snippet used:
<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 am unsure if there is a way to reset the data each time the modal is opened or if there is a different approach I should be considering. Despite searching extensively for a solution, I have not been able to find one.
Your assistance on this matter would be greatly appreciated!