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

TimeSocks's avatar

Improving a flawed system

I have quite a general question here, not a specific problem. I have a Vue + Laravel site that mainly - mainly - handles bookings for training courses. It also handles orders for a few physical products (textbooks), and handles people buying access to e-learning courses. So it has a custom basket and order processing system that handles these three distinct parts of each order. An order can consist of all 3 things at once, and so the backend has to be able to handle that 'all at once'.

The process for handling a course booking can be quite complex because each course is different. Each course can have multiple delegates. Some courses have exam fees, some don't. Some have a residential option, some don't. A customer might book a course where one delegate will take the residential option and another won't. Etc etc. And then of course they might also order access to an e-learning course, so a new user account has to be created, and so on.

At the moment, the controller for the checkout process is quite large and unwieldy. It handles all these different possibilities with functions all over the place.

From a design perspective, what is the best way to handle all these disparate elements? I've heard the phrase 'fat models, thin controllers' - at the moment the exact opposite is the case. I realise there's not much info to go on here, happy to elaborate further. I guess I'm looking for some general tips as to how things are best structured so I can research further.

0 likes
2 replies
scottHellings88's avatar

You could implement Services (not native to laravel so no artisan command to make them) and extract some of the logic out into app/Services/CartService.php There is a article that goes over something similar https://farhan.dev/tutorial/laravel-service-classes-explained/

If you aren't already you can make use of form requests to extract the validation out of your controller. https://laravel.com/docs/9.x/validation#form-request-validation

You could make use of global scopes in Laravel to extract some of the query logic and apply the scopes to your eloquent queries

https://laravel.com/docs/9.x/eloquent#local-scopes https://laravel.com/docs/9.x/eloquent#local-scopes

hope you find something useful from this

Please or to participate in this conversation.