Menu

Document Status Transitions in Laravel: Enums, Locked Transitions and a Status Log
📰

Document Status Transitions in Laravel: Enums, Locked Transitions and a Status Log

DEV Community: php·Tuğrul Yıldırım·about 6 hours ago
#4CEUhi5B
#devto#dev#status#quote#quotestatus
Reading 0:00
15s threshold

A quote in a business app looks like a simple record: a customer, some lines, a total, and a status column. Then one day someone finds an invoice that was created from a quote marked "rejected". Nobody can say how it got there. The UI hides the "Convert to order" button for rejected quotes, so it must have been something else: an old admin screen, an import script, a queue job that ran twice, or two people clicking at the same time.

The root cause is almost always the same. The status column is a free-text field that any code path can write to, and the rules about which status can follow which live in button visibility, not in the domain.

This post shows how I model document statuses in Laravel ERP and CRM apps so that the rules live in one place: a backed enum that knows its allowed transitions, a single service that performs every transition inside a locked transaction, a transition log, and a model guard that catches code paths that try to skip the service.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.