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

KayleeDebo's avatar

KayleeDebo wrote a reply+100 XP

4mos ago

No repeating Eloquent query statements in the mathods of a controller

You might want to write a Action Class for reusable code. (https://rezakhademix.medium.com/what-are-laravel-action-classes-and-how-to-use-them-253217c43b06)

Service class (with static functions) might also be right for your use case.

Repeating your code is always bad practice, try to resolve duplicate code by deciding what 'domain' it belongs to and write a appropriate Class object/function name.