I am having a bit of problem trying to find the correct place for business logic. The project I am working on isn't huge, but is not small either and has a very considerable importance in my company. That said, I'd like to know how to better organize my business logic. First an example of how things are today.
The method below is inside a service and is used to confirm a negociation. The method is used inside another method (newNegotiation) in the same same service, and all the method it calls are private. I picked specially this method because it has something inside of it that is the point of this post: the $this->confirmCart();. Also, the service is used inside a controller, as shown below.
public function acceptNegotiation() { try { DB::beginTransaction(); $this->getNegotiationData([4]); $this->generateIngressosCodes(); $this->confirmCart(); $this->registerConfirmedLog(); $this->sendConfirmedNegotiationEmail(); DB::commit(); return ['status' => true, 'msg' => "Negociação confirmada!"]; } catch (\Throwable $th) { DB::rollback(); return ['status' => false, 'msg' => $th->getMessage()]; } } The service being used inside the controller:
public function createNegotation(NegotitationRequest $request) { $this->funilSellService->setData($request->all()); $response = $this->funilSellService->newNegotiation(); if ($response['status']) { return response()->json($response['msg'], 200); } else { return response()->json($response['msg'], 400); } } So, about the $this->confirmCart() (as I said, it's a private method inside the service), but it just feels wrong to be called that and to be a method of a service. Thinking of the principle "tell, don't ask", it gets even weirder, because in this case, it seems better for the Cart to update itself: just tell it to (something like $cart->confirmPayment(), where the $cart is an instance of a model Cart). But this ideia of mine seems wrong when thinking of a model as a way for transfering data from the database to the rest of the application. If I go on with this ideia of placing business logic inside the model, I might end up having logic and a transfering layer mixed up.
As you can see, the slim controller seems fine, but the problem falls on where to put the business logic, since the service is coordinating some functions and the model should act as transfer layer, as far as I've read, differently from a Domain model (but I don't know if I should be using DDD with Laravel). Anyways, where to put the business logic?