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

herry_collins's avatar

Building a Simple Estimation Module in Laravel Need Some Advice

I’m working on a small Laravel project related to construction estimating, and I’m kinda stuck on how to structure it properly. Basically, it’s like an app where you add items, quantities, and rates to build an estimate, then generate a report or export it later. Right now I’m using Eloquent for most things but I’m not sure if I should move some logic into service classes or just keep it inside controllers. Also thinking about how to handle revisions like when the client changes something, how to store the old version safely. Another issue is when generating big PDF reports, sometimes it gets really slow or just times out 😅. Anyone here dealt with that before? Would appreciate any tips or ideas. Just trying to make it clean and scalable before it turns into spaghetti later. Thanks!

0 likes
1 reply
martinbean's avatar

@herry_collins You need to break your requirements and functionality down into steps. You‘ve listed at least three different things:

  • Estimations
  • Revisions of estimates
  • Exporting estimates as PDFs

Tackle each thing independently, otherwise you’re just going to get overwhelmed.

As for how to structure things, I’d certainly keep business logic extracted in a dedicated class rather than stuffing it all in a controller action somewhere. If estimates are essentially quotes with line items and quantities, then I’d model it as such: a parent Estimate model, that has many EstimateItem models. You could then have an EstimateService class that uses a builder pattern for creating estimates (similar to Cashier’s newSubscription method):

$estimate = $this->estimateService->newEstimate()
    ->addItem($product1, $quantity1)
    ->addItem($product2, $quantity2)
    ->create();

When it comes to adding revisions, your changes would then be contained in just your estimate service class and its method for updating estimates:

$estimate = $this->estimateService->update($estimate, $newItems);

Finally, for exporting estimates as PDFs, it shouldn’t take too long if all you‘re doing is fetching records from a database and rendering them in a template. But if it is, you can push it to a queue, and just send a notification with a download link to the user when it’s ready:

class ExportEstaimte
{
    use Queueable;

    public function __construct(protected Estimate $estimate) {}

    public function handle()
    {
        // Generate PDF...

        $this->estimate->customer->notify(new EstimateReadyNotification($this->estimate));
    }
}
1 like

Please or to participate in this conversation.