app/Jobs/ImportProfession.php: in getRecipe() sync the reagent's instead of only process them on recipe create.
This commit is contained in:
parent
8fd07c11a8
commit
9da87b2b95
1 changed files with 14 additions and 11 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue