Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

justl00king's avatar

Help Understanding Laravel - Where to Put Logic

Here is what I have so far. My app has several controllers and inside 2 different controllers, I'm handling forms through several of the methods in these controllers. I need to create a user record in the user table as well as create records in several other related tables for subscriptions, notes, etc and then I also need to send an email to myself and the new user. Also, I'm pushing all the user data to a third party contact management system (CMS).

In order to cut down on writing the logic for creating each of these records in different the controllers, I've prepared all the data and passed it through to my User model into a method called signUp().

Everything is working great, but the signUp() method is really, really big. I was thinking that I should clean it up by breaking out the following parts and put them into their own methods so I can the refactor them to reduce the amount of logic I have and then just call these new methods from inside my signUp() function:

  1. emails that I'm sending to myself and the new user (there are 5 different email versions and depending on which form was filled out, one of them is sent. So, I'm calling a different view file for each version. Also, I'm using the queue when sending them)

  2. sending the data to the third party cms (I'm dispatching a job. Depending on which form was filled out different information is sent to the third party CMS)

My question is this, do I:

  1. Leave them alone (leave them inside the signUp() method)
  2. Move them to their own methods inside the User model and call them from inside the signUp() method
  3. Move them somewhere else

If the answer is 3, where would I move the logic to? For the email logic, should I create a file in \app\Mail folder? And for the logic to send to the third party CMS, where should that go?

Thanks so much for your help!

0 likes
1 reply

Please or to participate in this conversation.