From 0ff095302c55570c5eab1516b688e67b0277278d Mon Sep 17 00:00:00 2001 From: Jay Sizzla Date: Sat, 13 Apr 2024 20:26:47 +0200 Subject: [PATCH] Add search for title and year --- app/Http/Livewire/MissingMediaSearch.php | 8 +++++ .../livewire/missing-media-search.blade.php | 36 +++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/MissingMediaSearch.php b/app/Http/Livewire/MissingMediaSearch.php index 8fe342ce3a..ce0602f66e 100644 --- a/app/Http/Livewire/MissingMediaSearch.php +++ b/app/Http/Livewire/MissingMediaSearch.php @@ -28,6 +28,12 @@ class MissingMediaSearch extends Component #TODO: Update URL attributes once Livewire 3 fixes upstream bug. See: https://github.com/livewire/livewire/discussions/7746 + #[Url(history: true)] + public string $name = ''; + + #[Url(history: true)] + public ?int $year = null; + #[Url(history: true)] public array $categories = []; @@ -47,6 +53,8 @@ class MissingMediaSearch extends Component final public function medias(): \Illuminate\Contracts\Pagination\LengthAwarePaginator { return Movie::with(['torrents:tmdb,resolution_id,type_id' => ['resolution:id,position,name']]) + ->when($this->name, fn ($query) => $query->where('title', 'LIKE', '%'.$this->name.'%')) + ->when($this->year, fn ($query) => $query->where('release_date', 'LIKE', '%'.$this->year.'%')) ->withCount(['requests' => fn ($query) => $query->whereNull('torrent_id')->whereNull('claimed')]) ->orderBy($this->sortField, $this->sortDirection) ->paginate($this->perPage); diff --git a/resources/views/livewire/missing-media-search.blade.php b/resources/views/livewire/missing-media-search.blade.php index 0e9ea1cdca..f520d8fd7b 100644 --- a/resources/views/livewire/missing-media-search.blade.php +++ b/resources/views/livewire/missing-media-search.blade.php @@ -1,10 +1,42 @@
-

Missing Media

+
+

Missing Media

+
+
+
+ + +
+
+
+
+ + +
+
+
+
- {{ __('common.name') }} + {{ __('torrent.title') }} @include('livewire.includes._sort-icon', ['field' => 'title'])