Files
opentextsummaries/resources/views/books/index.blade.php
T
2025-09-20 16:47:41 +03:00

98 lines
5.3 KiB
PHP

@extends('layouts.app')
@section('content')
<h1 class="text-3xl font-bold text-indigo-700 mb-6">All Books</h1>
<form method="GET" action="{{ route('books.index') }}" class="bg-white rounded-lg shadow p-4 mb-6">
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700">Search</label>
<input type="text" name="q" value="{{ $filters['q'] ?? '' }}" placeholder="Title or description..." class="mt-1 w-full border-gray-300 rounded-md" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Category</label>
<select name="category" class="mt-1 w-full border-gray-300 rounded-md">
<option value="">All</option>
@foreach($categories as $cat)
<option value="{{ $cat->slug }}" {{ ($filters['category'] ?? '') == $cat->slug || ($filters['category'] ?? '') == (string)$cat->id ? 'selected' : '' }}>{{ $cat->name }}</option>
@endforeach
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Author</label>
<select name="author" class="mt-1 w-full border-gray-300 rounded-md">
<option value="">All</option>
@foreach($authors as $auth)
<option value="{{ $auth->slug }}" {{ ($filters['author'] ?? '') == $auth->slug || ($filters['author'] ?? '') == (string)$auth->id ? 'selected' : '' }}>{{ $auth->name }}</option>
@endforeach
</select>
</div>
<div class="grid grid-cols-2 gap-2">
<div>
<label class="block text-sm font-medium text-gray-700">From</label>
<input type="date" name="date_from" value="{{ $filters['date_from'] ?? '' }}" class="mt-1 w-full border-gray-300 rounded-md" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">To</label>
<input type="date" name="date_to" value="{{ $filters['date_to'] ?? '' }}" class="mt-1 w-full border-gray-300 rounded-md" />
</div>
</div>
</div>
<div class="mt-4 flex items-center gap-3">
<button type="submit" class="px-4 py-2 bg-indigo-600 text-white rounded-md">Filter</button>
<a href="{{ route('books.index') }}" class="px-4 py-2 bg-gray-100 text-gray-800 rounded-md">Reset</a>
</div>
</form>
@if($books->count() === 0)
<div class="bg-white rounded-lg shadow p-6 text-center text-gray-600">No books found.</div>
@else
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
@foreach($books as $book)
<div class="bg-white rounded-lg shadow overflow-hidden">
@if($book->cover_image)
<img src="{{ $book->cover_image }}" alt="{{ $book->title }} cover" class="w-full h-48 object-cover" />
@else
<div class="w-full h-48 bg-gray-200 flex items-center justify-center text-gray-500">No Cover</div>
@endif
<div class="p-4">
<h2 class="text-lg font-semibold"><a href="{{ route('books.show', $book) }}" class="hover:underline">{{ $book->title }}</a></h2>
<p class="text-sm text-gray-600">
@if($book->authors && $book->authors->count())
{{ $book->authors->pluck('name')->join(', ') }}
@elseif($book->author)
{{ $book->author }}
@endif
</p>
@if($book->category)
<p class="text-xs text-gray-500 mt-1">Category: {{ $book->category->name }}</p>
@endif
@auth
<div class="mt-3">
@php($inReadlist = auth()->user()->readlistBooks()->where('book_id', $book->id)->exists())
@if(!$inReadlist)
<form action="{{ route('readlist.store', $book) }}" method="POST">
@csrf
<button type="submit" class="px-3 py-2 text-sm bg-indigo-600 hover:bg-indigo-700 text-white rounded-md">Add to Readlist</button>
</form>
@else
<form action="{{ route('readlist.destroy', $book) }}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="px-3 py-2 text-sm bg-red-50 text-red-700 hover:bg-red-100 rounded-md">Remove</button>
</form>
@endif
</div>
@endauth
</div>
</div>
@endforeach
</div>
<div class="mt-6">
{{ $books->links() }}
</div>
@endif
@endsection