Reputation: 195
Does calling a database transaction in the Controller a good practice? if no where should i proper call a database transaction?
Upvotes: 0
Views: 532
Reputation: 327
Or you can search for Command Bus pattern
https://github.com/tillkruss/laravel-tactician
This package implements the Command Bus pattern easily with Laravel. It comes with a database transaction middleware and Command Bus is good for a scalable application moving the logic from controllers to Command Handlers.
Upvotes: 0
Reputation: 353
Depends upon the size of project and personal preference also. But calling a database transaction outside of controller is a better practice as its makes your code clean and understandable. Also you can use the same function for multiple controllers reducing the pain of redundant coding. You can search for SOA (Service Oriented Architecture) and use it for better practice.
Upvotes: 1