vlad awtsu
vlad awtsu

Reputation: 195

Laravel controller calling database transaction

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

Answers (2)

everytimeicob
everytimeicob

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

Saurav
Saurav

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

Related Questions