1
0
Fork 0

app/Jobs/ImportProfession.php: in getRecipe() sync the reagent's instead of only process them on recipe create.

This commit is contained in:
Henrik Hautakoski 2021-07-01 14:42:24 +02:00
parent 8fd07c11a8
commit 9da87b2b95

View file

@ -129,19 +129,22 @@ class ImportProfession implements ShouldQueue
'item_id' => $item->id,
'category_id' => $category->id
]);
// Reagents
foreach($data->items as $reagent) {
$item = Item::where('name', $reagent->name)->first();
if (!$item) {
throw new Exception("Could not find item '{$reagent->name}'");
}
$recipe->reagents()->attach($item, [ 'quantity' => $reagent->num ]);
}
$recipe->push();
}
// Insert/Update Reagents
$reagents = [];
foreach($data->items as $reagent) {
$item = Item::where('name', $reagent->name)->first();
if (!$item) {
throw new Exception("Could not find item '{$reagent->name}'");
}
$reagents[$item->id] = [ 'quantity' => $reagent->num ];
}
$recipe->reagents()->sync($reagents);
return $recipe;
}
}