Adding Item Page
This commit is contained in:
parent
868d49af23
commit
ac7e64c75c
6 changed files with 148 additions and 0 deletions
27
app/Http/Controllers/ItemController.php
Normal file
27
app/Http/Controllers/ItemController.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
43
app/Http/Livewire/Items.php
Normal file
43
app/Http/Livewire/Items.php
Normal 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)
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue