In this episode, we dive into the process of allowing an admin user to change the role of a team member through a modal popup. Here's what we tackle step-by-step:
First, we sort out permissions—making sure that only users with the right role (like an admin) can even see the option to change someone else's role. We use Laravel's policies to handle this logic, and update our templates so that only permitted users get the dropdown option to trigger the modal.
Next, we add the actual modal that will pop up when you click to change a role. Instead of building everything from scratch, we borrow modal code from Laravel Breeze's delete user form, adjusting it to fit our needs. We make sure each modal is unique by including the member’s ID, so you won't get any weird overlaps.
Inside the modal, we build a simple form: there's a dropdown listing all available roles, pre-selected to show the member’s current role. We also make sure everything's styled nicely and labels are accessible for screen readers.
By the end of the episode, we've got a working modal that allows an admin to pick a new role for any team member (except themselves, unless you choose to allow it!). Permissions are double-checked all the way, and regular team members won't see any of these options. Next time, we'll hook up the form to actually submit the change and make sure it sticks!