A controller coordinates an HTTP request and application response. It should generally remain focused on request-level orchestration rather than becoming a giant business-logic class.
Example:
public function store(StoreProductRequest $request)
{
$product = $this->productService->create(
$request->validated()
);
return redirect()->route('products.show', $product);
}
Scenario:
If a controller contains validation, payment processing, inventory calculations, email delivery, reporting, and ten database queries, maintenance becomes difficult. Those responsibilities can be separated into requests, services, domain classes, jobs, and models where appropriate.
There is no universal requirement that every controller must call a service. Simple CRUD operations can remain simple. The goal is cohesive, maintainable code.
0 comments:
Post a Comment
Thanks