Conversation
… creation When a user creates an order via the order/form component without filling in the orchestrator constraints section, the frontend sends orchestrator_priority as null (or omits it entirely). Both controllers use request->only([..., 'orchestrator_priority']), which returns null for keys absent from the request. That explicit null is then forwarded to Order::create() / Order::update(), bypassing MySQL's column-level default of 50 and raising: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'orchestrator_priority' cannot be null Root cause ---------- The migration defines the column as NOT NULL with a DB default of 50, but Eloquent's INSERT statement includes every key present in the input array — even when the value is null — so the DB default is never used. Fix (defence-in-depth, three layers) -------------------------------------- 1. Order model — $attributes default: Added protected $attributes = ['orchestrator_priority' => 50] so that any new Order instance starts with a valid value before any input is applied. 2. Order model — setOrchestratorPriorityAttribute mutator: Coerces null or non-numeric values to 50 at the model layer, ensuring the constraint can never be violated regardless of the call site. 3. Controllers — explicit null-guard before create/update: Both Api\v1\OrderController (create + update) and Internal\v1\OrderController (createRecord) now check whether orchestrator_priority is missing or non-numeric and set it to 50 before passing $input to Eloquent. This mirrors the existing pattern used for 'type' and 'status'. 4. Migration — make column nullable: Added a new migration (2026_04_20_000001) that alters the column to nullable on existing installations that have already run the original migration. The application layer guarantees 50 is always written, so NULL will not appear in practice; nullable is a belt-and-suspenders safety net.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user creates an order via the
order/formcomponent without filling in the orchestrator constraints section (Orchestrator Priority, Required Skills, Time Window), the following error is thrown:Root Cause
The migration
2026_04_08_000003_add_orchestrator_columns_to_orders_tabledefinesorchestrator_priorityasNOT NULLwith a database-leveldefault(50). However, MySQL's column default is only used when the column is omitted from theINSERTstatement entirely. When Eloquent receives an explicitnullfor the key, it includesorchestrator_priority = NULLin theINSERT, which violates theNOT NULLconstraint and bypasses the DB default.Both controllers use
$request->only([..., 'orchestrator_priority']), which returnsnullfor any key absent from the request payload. Thatnullis then forwarded directly toOrder::create()/Order::update().Fix — Defence-in-depth across four layers
1.
Ordermodel —$attributesdefaultAdded
protected $attributes = ['orchestrator_priority' => 50]so every newOrderinstance starts with a valid value before any input is applied.2.
Ordermodel —setOrchestratorPriorityAttributemutatorA new Eloquent mutator coerces
nullor any non-numeric value to50at the model layer, ensuring the constraint can never be violated regardless of the call site — including future code paths not yet written.3. Controllers — explicit null-guard before
create/updateBoth
Api\v1\OrderController(create + update) andInternal\v1\OrderController(createRecord) now check whetherorchestrator_priorityis missing or non-numeric and default it to50before passing$inputto Eloquent. This mirrors the existing pattern already used fortypeandstatus.4. New migration — make column nullable for existing installations
Added
2026_04_20_000001_make_orchestrator_priority_nullable_on_orders_tablewhich alters the column tonullableon databases that have already run the original migration. The application layer guarantees50is always written, soNULLwill not appear in practice; thenullableflag is a belt-and-suspenders safety net.Files Changed
server/src/Models/Order.php$attributesdefault +setOrchestratorPriorityAttributemutatorserver/src/Http/Controllers/Internal/v1/OrderController.phpcreateRecordbefore-callbackserver/src/Http/Controllers/Api/v1/OrderController.phpcreateandupdatemethodsserver/migrations/2026_04_20_000001_make_orchestrator_priority_nullable_on_orders_table.phpTesting
To reproduce the bug before this fix:
SQLSTATE[23000]error is returnedAfter this fix, the order is created successfully with
orchestrator_priority = 50(the default).