How to properly structure a model in MVC on PHP? Problems with Fat Model and business logic
Hello everyone! I'm a beginner PHP developer and have been writing in Laravel for several months. But I feel like I'm doing something wrong with models.
I have an online store project. Initially, I put all the logic into Eloquent models. For example, my Order model contains:
class Order extends Model
{
public function calculateTotalWithDiscount($couponCode) { ... }
public function validateStock() { ... }
public function sendConfirmationEmail() { ... }
public function generateInvoicePdf() { ... }
public function applyLoyaltyPoints($userId) { ... }
public function checkFraud() { ... }
}
Now this model has over 2000 lines. I understand this is a "Fat Model", but I don't know how to properly separate it.