Not really sure what the question is here? I would just create an action that handles it. The logic sound pretty simple
Add email to a group and create it if it not exists
Hello,
I have this situation.
An authenticated user has itw own account and can invite some other users to join his group to collaborate on the same datas.
Each user has his own group (belongsTo) and can be in several groups (belongsToMany).
The group owner wants to invite [email protected], so he types [email protected] in the input field and clicks on the add button.
When he clicks on the add button, it calls the method add in a controller. But this method has only the purpose of adding the user to the owner group.
I need this scenario :
-
click on the
addbutton -
check if the user exists
-
if he doesn't exist, create it and add it to the owner group
-
else if he already exists, add it to the owner group
I'm confused on how to write this in the code. Well the code isn't a problem, I know how to write it, but I mean where do I have to write it, I don't succeed imagine the logic, which method in which controller, ...
I already did such manipulations, I had written the different actions in the same method, but is it really the better way ? I mean the code to create a user should in only one method. And the code to add an existing user to a group should also be in only one method.
Can you help me please ?
Thank you very much.
Vincent
@vincent15000 yeah totally. But an action can be tested by itself and can be reused. Say you later want to add a command that does the same. You just reuse the action
Please or to participate in this conversation.