Archived
1
0
Fork 0

Adding Item Page

This commit is contained in:
Henrik Hautakoski 2021-07-30 12:31:31 +02:00
parent 868d49af23
commit ac7e64c75c
6 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers;
use App\Models\Item;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class ItemController extends Controller
{
/**
* List all recipies
*/
public function index()
{
return view('item.index');
}
/**
* Show a recipe
*/
public function show(Item $item)
{
return view('item.show', compact('item'));
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Http\Livewire;
use App\Models\Item;
use Livewire\Component;
class Items extends Component
{
use Traits\WithPagination;
protected $queryString = [
'name' => ['except' => ''],
'reagent_for' => ['except' => false],
];
/**
* Filter by name
*/
public string $name = '';
public $reagent_for = false;
public function render()
{
$query = Item::query()
->with(['reagent_for']);
if ($this->reagent_for) {
$query->has('reagent_for');
}
// Filter by name
if (strlen($this->name) >= 3) {
$query->where('name', 'LIKE', '%' . $this->name . '%');
}
return view('livewire.items', [
'items' => $query->paginate($this->perPage)
]);
}
}

View file

@ -0,0 +1,8 @@
<x-layout name="app">
<x-slot name="title">{{ __('Items') }}</x-slot>
<div class="p-4">
<livewire:items />
</div>
</x-layout>

View file

@ -0,0 +1,8 @@
<x-layout name="app">
<x-slot name="title">{{ __('Item') }} - {{ $item->name }}</x-slot>
<div class="p-4">
</div>
</x-layout>

View file

@ -0,0 +1,55 @@
<div>
<div class="grid grid-cols-2 gap-4 mb-2">
<x-input wire:model="name" name="name" placeholder="{{ __('Name') }}" />
<div class="flex items-center">
<label for="reagent_for" class="mr-2">{{ __('Only reagents') }}</label>
<x-checkbox wire:model="reagent_for" name="reagent_for" />
</div>
</div>
@if ($items->count())
<table class="w-full whitespace-nowrap">
<thead>
<tr tabindex="0" class="focus:outline-none w-full text-sm leading-none text-gray-800">
<th class="text-left w-1/4 px-3 py-4">{{ __('Name') }}</th>
<th class="text-left w-3/4 px-3 py-4">{{ __('Reagent for') }}</th>
</tr>
</thead>
<tbody class="w-full">
@foreach($items as $item)
<tr class="focus:outline-none text-sm leading-none text-gray-800 bg-white hover:bg-gray-100 border-b border-t border-gray-100">
<td class="px-3 py-4">
<x-wowhead-link type="item" :wh-id="$item->external_id" href="{{ route('item.show', [ 'item' => $item ]) }}">
{{ $item->name }}
</x-wowhead-link>
</td>
<td class="px-3 py-4">
@if ($item->reagent_for && $item->reagent_for->count() > 0)
<ul class="flex flex-wrap items-center gap-2">
@foreach($item->reagent_for->take(15) as $recipe)
<li>
<x-recipe-link :recipe="$recipe" />
</li>
@endforeach
@if ($item->reagent_for->count() > 15)
<li>and <strong>{{ $item->reagent_for->count() - 15 }}</strong> more</li>
@endif
</ul>
@else
<span class="text-gray-400">{{ __('None') }}</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="mt-4">
{{ $items->links() }}
</div>
@else
<x-empty-result>No items found</x-empty-result>
@endif
</div>

View file

@ -8,6 +8,7 @@ use App\Http\Controllers\CharacterController;
use App\Http\Controllers\CharacterProfessionController;
use App\Http\Controllers\ProfessionController;
use App\Http\Controllers\RecipeController;
use App\Http\Controllers\ItemController;
use App\Http\Controllers\Auth\SessionController;
@ -68,6 +69,12 @@ Route::prefix('recipes')->name('recipe.')->group(function () {
Route::get('/{recipe}', [RecipeController::class, 'show'])->name('show');
});
// Items
Route::prefix('items')->name('item.')->group(function () {
Route::get('/', [ItemController::class, 'index'])->name('index');
Route::get('/{item}', [ItemController::class, 'show'])->name('show');
});
// Authenticated section
// ----------------------------
Route::middleware(['auth'])->group(function() {