I'm trying to make an editor page for what is probably best described as a User/Role editor. (A page where an admin can assign Users to a Role)
There is a User model and a Role model which have a many-to-many relationship. I am fine with setting up the pivot table and adding the relationship to the models. I also have functioning User and Role restfull controllers. I'm a little hung up on how I should create this editor page in a 'Laravel' like way.
(A) If I was using vanilla PHP I would probably make a post request including the role_id and user_ids[] array and build all the logic to update the DB from there.
(B) If I was using Vue/JS/AJAX I could create a restfull controller 'UserRoleController' representing each row in the pivot table and make a rest call for each add/remove action. ( would prefer to keep this serverside only if possible for now, maybe need a little ajax for the list of users which can be added but that's it)
So currently my feeling is to take my restfull RoleController and add a method called something like 'syncUsers($request)' and create an addition link to this method in routes.php and make it a POST or PUT/PATCH at '../role/syncusers/'? (I would put this above the resourceful route in case someone creates a role called syncusers.) Then it would be easy to pull the IDs and use $role->users()->sync(...) to persist.
Is this the right way to go about this or is there a more 'laravel like' clean way?
Thanks!
let me know if further clarification is needed