Skip to content

Commit

Permalink
Inventory Phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed May 3, 2024
1 parent 2979823 commit c3ff0dc
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 15 additions & 5 deletions app/Http/Controllers/Entity/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions app/Http/Requests/StoreInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
41 changes: 41 additions & 0 deletions app/Http/Requests/UpdateInventory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Requests;

use App\Traits\ApiRequest;
use Illuminate\Foundation\Http\FormRequest;

class UpdateInventory extends FormRequest
{
use ApiRequest;

/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return $this->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',
]);
}
}
3 changes: 2 additions & 1 deletion resources/views/cruds/fields/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<x-forms.foreign
:campaign="$campaign"
name="item_id"
:name=" $multiple ? 'item_id[]' : 'item_id'"
key="item"
entityType="items"
:required="$required ?? false"
Expand All @@ -26,6 +26,7 @@
:class="\App\Models\Item::class"
:selected="$preset"
:helper="$helper ?? null"
:multiple="$multiple"
:dropdownParent="$dropdownParent ?? null"
:entityTypeID="config('entities.ids.item')">
</x-forms.foreign>
1 change: 1 addition & 0 deletions resources/views/entities/pages/inventory/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'allowNew' => false,
'dropdownParent' => request()->ajax() ? '#inventory-dialog' : null,
'required' => true,
'multiple' => isset($multiple),
])

<x-forms.field
Expand Down
1 change: 1 addition & 0 deletions resources/views/entities/pages/inventory/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'content' => 'entities.pages.inventory._form',
'submit' => __('entities/inventories.actions.add'),
'dialog' => true,
'multiple' => true,
])
{!! Form::hidden('entity_id', $entity->id) !!}
{!! Form::close() !!}
Expand Down

0 comments on commit c3ff0dc

Please sign in to comment.