diff --git a/app/Http/Controllers/Api/v1/EntityInventoryApiController.php b/app/Http/Controllers/Api/v1/EntityInventoryApiController.php index 960cce9a87..e72f4b72b8 100644 --- a/app/Http/Controllers/Api/v1/EntityInventoryApiController.php +++ b/app/Http/Controllers/Api/v1/EntityInventoryApiController.php @@ -4,7 +4,7 @@ use App\Models\Campaign; use App\Models\Entity; -use App\Http\Requests\StoreInventory as Request; +use App\Http\Requests\UpdateInventory as Request; use App\Http\Resources\InventoryResource as Resource; use App\Models\Inventory; diff --git a/app/Http/Controllers/Entity/InventoryController.php b/app/Http/Controllers/Entity/InventoryController.php index 8ad6a88368..853e5c7b7c 100644 --- a/app/Http/Controllers/Entity/InventoryController.php +++ b/app/Http/Controllers/Entity/InventoryController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\StoreInventory; +use App\Http\Requests\UpdateInventory; use App\Http\Requests\CopyInventory; use App\Models\Campaign; use App\Models\Entity; @@ -79,11 +80,20 @@ public function store(StoreInventory $request, Campaign $campaign, Entity $entit if ($request->ajax()) { return response()->json(['success' => true]); } + $itemIds = $request->only('item_id')['item_id']; + if (isset($itemIds)) { + foreach ($itemIds as $id) { + $data = $request->only($this->fillable); + $data['item_id'] = $id; + $inventory = new Inventory(); + $inventory = $inventory->create($data); + } + } else { + $data = $request->only($this->fillable); + $inventory = new Inventory(); + $inventory = $inventory->create($data); + } - $data = $request->only($this->fillable); - - $inventory = new Inventory(); - $inventory = $inventory->create($data); return redirect() ->route('entities.inventory', [$campaign, $entity]) @@ -117,7 +127,7 @@ public function edit(Campaign $campaign, Entity $entity, Inventory $inventory) /** */ - public function update(StoreInventory $request, Campaign $campaign, Entity $entity, Inventory $inventory) + public function update(UpdateInventory $request, Campaign $campaign, Entity $entity, Inventory $inventory) { $this->authorize('update', $entity->child); diff --git a/app/Http/Requests/StoreInventory.php b/app/Http/Requests/StoreInventory.php index 058e1ab4ea..8bf39eb47c 100644 --- a/app/Http/Requests/StoreInventory.php +++ b/app/Http/Requests/StoreInventory.php @@ -28,9 +28,8 @@ public function rules() { return $this->clean([ 'entity_id' => 'required|exists:entities,id', - 'item_ids' => 'nullable|array|required_without:name', - 'item_ids.*' => 'exists:items,id', - //'item_id' => 'nullable|required_without:name|exists:items,id', + 'item_id' => 'nullable|array|required_without:name', + 'item_id.*' => 'exists:items,id', 'name' => 'nullable|string|required_without:item_id', 'amount' => 'required|numeric', 'position' => 'nullable|string|max:191', diff --git a/app/Http/Requests/UpdateInventory.php b/app/Http/Requests/UpdateInventory.php new file mode 100644 index 0000000000..750add2a32 --- /dev/null +++ b/app/Http/Requests/UpdateInventory.php @@ -0,0 +1,41 @@ +clean([ + 'entity_id' => 'required|exists:entities,id', + 'item_id' => 'nullable|required_without:name|exists:items,id', + 'name' => 'nullable|string|required_without:item_id', + 'amount' => 'required|numeric', + 'position' => 'nullable|string|max:191', + 'description' => 'nullable|string|max:191', + 'visibility_id' => 'nullable|exists:visibilities,id', + 'image_uuid' => 'nullable|exists:images,id', + 'is_equipped' => 'boolean', + ]); + } +} diff --git a/resources/views/cruds/fields/item.blade.php b/resources/views/cruds/fields/item.blade.php index c0827419df..c21a4eac33 100644 --- a/resources/views/cruds/fields/item.blade.php +++ b/resources/views/cruds/fields/item.blade.php @@ -15,7 +15,7 @@ diff --git a/resources/views/entities/pages/inventory/_form.blade.php b/resources/views/entities/pages/inventory/_form.blade.php index 23a6cee62f..e12ac28fe3 100644 --- a/resources/views/entities/pages/inventory/_form.blade.php +++ b/resources/views/entities/pages/inventory/_form.blade.php @@ -14,6 +14,7 @@ 'allowNew' => false, 'dropdownParent' => request()->ajax() ? '#inventory-dialog' : null, 'required' => true, + 'multiple' => isset($multiple), ]) 'entities.pages.inventory._form', 'submit' => __('entities/inventories.actions.add'), 'dialog' => true, + 'multiple' => true, ]) {!! Form::hidden('entity_id', $entity->id) !!} {!! Form::close() !!}