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)
]);
}
}