Update LOT API to use nested batch_origin_entries structure
Deploy / deploy (push) Successful in 14s
Deploy / deploy (push) Successful in 14s
Each spice now returns an `origins` array (was single `origin` object) with supplier and farmer resolved from the new entries relation, not flat columns. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a98beeb45
commit
7c0fde4fd5
2 files changed
+10
-7
No files matched your search
@@ -16,7 +16,8 @@ class LotController extends Controller
|
||||
'size.packing',
|
||||
'recipe.spices',
|
||||
'origins.spice',
|
||||
'origins.supplier',
|
||||
'origins.entries.supplier',
|
||||
'origins.entries.farmer',
|
||||
])->where('lot_number', $lotNumber)->first();
|
||||
|
||||
if (! $batch) {
|
||||
|
||||
@@ -35,12 +35,14 @@ class LotResource extends JsonResource
|
||||
return [
|
||||
'name' => $spice->name,
|
||||
'percentage' => (float) $spice->pivot->amount_in_percent,
|
||||
'origin' => $origin ? [
|
||||
'country' => $origin->origin_country,
|
||||
'farmer' => $origin->farmer,
|
||||
'supplier' => $origin->supplier?->name,
|
||||
'notes' => $origin->notes,
|
||||
] : null,
|
||||
'origins' => $origin
|
||||
? $origin->entries->map(fn ($e) => [
|
||||
'country' => $e->origin_country,
|
||||
'supplier' => $e->supplier?->name,
|
||||
'farmer' => $e->farmer?->name,
|
||||
'notes' => $e->notes,
|
||||
])->values()
|
||||
: [],
|
||||
];
|
||||
})->values(),
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user