1 year ago

Best way to separate my code

Posted 1 year ago by deansatch

Lets say I have a front end system and a backend system. On the frontend a visitor can place an order and will be automatically registered as a 'user', they will also be a 'customer' with an 'order'. On the backend an admin would be able to add a 'customer', optionally then add a user for that customer, and at any time add an 'order'

For the backend it is quite straight forward that I can create a user or a customer and link them together at any point with a pivot table. Adding an order of course is also straight forward. But for the front end forcing all 3 to happen I'd need to call each of those functions.

What would be the best way to organise these 3 'tasks'? Are they Events? Jobs? Or just simple public methods that I should call sequentially in a transaction in my controllers?

Basically I'm thinking it would be nice to be able to (from anywhere) createUser()...or createCustomer() or - createUser() with createCustomer() instead of createUser(), createCustomer(), linkUserAndCustomer()

Apologies for not using actual code, I'm looking more for the best practice as opposed to code examples.

Please sign in or create an account to participate in this conversation.