Update LOT API to use nested batch_origin_entries structure
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:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 20:07:53 +02:00
1 parent 4a98beeb45
commit 7c0fde4fd5
2 files changed
+10 -7

No files matched your search

+2 -1
View File
@@ -16,7 +16,8 @@ class LotController extends Controller
'size.packing', 'size.packing',
'recipe.spices', 'recipe.spices',
'origins.spice', 'origins.spice',
'origins.supplier', 'origins.entries.supplier',
'origins.entries.farmer',
])->where('lot_number', $lotNumber)->first(); ])->where('lot_number', $lotNumber)->first();
if (! $batch) { if (! $batch) {
+8 -6
View File
@@ -35,12 +35,14 @@ class LotResource extends JsonResource
return [ return [
'name' => $spice->name, 'name' => $spice->name,
'percentage' => (float) $spice->pivot->amount_in_percent, 'percentage' => (float) $spice->pivot->amount_in_percent,
'origin' => $origin ? [ 'origins' => $origin
'country' => $origin->origin_country, ? $origin->entries->map(fn ($e) => [
'farmer' => $origin->farmer, 'country' => $e->origin_country,
'supplier' => $origin->supplier?->name, 'supplier' => $e->supplier?->name,
'notes' => $origin->notes, 'farmer' => $e->farmer?->name,
] : null, 'notes' => $e->notes,
])->values()
: [],
]; ];
})->values(), })->values(),
]; ];