Skip to content

Commit

Permalink
Add guest view
Browse files Browse the repository at this point in the history
  • Loading branch information
flemming-pr committed Mar 22, 2024
1 parent 33ce607 commit 719d5bb
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class ItemController extends Controller
{
public function guest(): View
{
return view('templates.item.guest');
}

public function index(): View
{
return view('templates.item.index');
Expand Down
34 changes: 34 additions & 0 deletions app/Livewire/ItemsGuest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Livewire;

use Livewire\Component;
use App\Models\Item;
use App\Models\Tag;

class ItemsGuest extends Component
{
public $items;
public $tags;

public function mount()
{
$this->items = Item::all();
$this->tags = Tag::all();
}

public function render()
{
return view('livewire.items-guest');
}

public function filter($tagId = null)
{
if ($tagId == null) {
$this->items = Item::all();
return;
}

$this->items = Tag::find($tagId)->items;
}
}
21 changes: 21 additions & 0 deletions resources/views/components/card.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@props([
'name' => '',
'image' => null,
'description' => '',
'tags' => [],
])

<div class="card bg-base-100 shadow-xl mb-4">
@if ($image)
<img class="object-cover rounded-l" loading="lazy" width="200" height="200" src="{{ asset('storage/' . $image) }}" alt="{{ $name }}">
@endif
<div class="card-body">
<h2 class="card-title">{{ $name }}</h2>
<p>{{ $description }}</p>
<div>
@foreach ($tags as $tag)
@include('partials.badges.default', ['title' => $tag->title])
@endforeach
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions resources/views/livewire/items-guest.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div>
<section class="pb-4 mb-4 border-b-2 border-solid">
<button class="badge badge-outline" wire:click="filter" >{{ __('All') }}</button>
@foreach ($tags as $tag)
<button class="badge badge-outline" wire:click="filter({{ $tag->id }})" >{{ $tag->title }}</button>
@endforeach
</section>
<section class="grid md:grid-cols-2 lg:grid-cols-3">
@foreach ($items as $item)
<x-card :name="$item->name" :image="$item->image" :description="$item->description" :tags="$item->tags"/>
@endforeach
</section>
</div>
6 changes: 3 additions & 3 deletions resources/views/partials/header.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<header>
<div class="navbar bg-base-100">
<div class="flex-1">
<a class="btn btn-ghost text-xl">{{ config('app.name') }}</a>
<a href="{{ route('home') }}" class="btn btn-ghost text-xl">{{ config('app.name') }}</a>
</div>
<div class="flex-none">
<ul class="menu menu-horizontal px-1">
<li><a href="{{ route('item.index') }}">{{ __('Items') }}</a></li>
<li><a href="{{ route('storageLocation.index') }}">{{ __('Storagelocations') }}</a></li>
<li><a href="{{ route('item.index') }}">{{ __('Borrow items') }}</a></li>
<li><a href="{{ route('storageLocation.index') }}">{{ __('Storage Locations') }}</a></li>
</ul>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/templates/item/guest.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<x-layout>
@livewire('items-guest')
</x-layout>
2 changes: 1 addition & 1 deletion resources/views/templates/item/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<x-layout>
@livewire('index-items')
@livewire('index-items')
</x-layout>
6 changes: 3 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Http\Controllers\ItemController;
use App\Http\Controllers\StorageLocationController;
use App\Http\Controllers\TransactionController;
use App\Models\Item;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -16,10 +17,9 @@
|
*/

Route::group(['middleware' => 'auth.basic'], function () {

Route::redirect('/', '/items');
Route::get('/', [ItemController::class, 'guest'])->name('home');

Route::group(['middleware' => 'auth.basic'], function () {
Route::group(['middleware' => 'auth.basic'], function () {
Route::group(['prefix' => 'items'], function () {
Route::get('/', [ItemController::class, 'index'])->name('item.index');
Expand Down

0 comments on commit 719d5bb

Please sign in to comment.