update: only include companies/networks with torrents in mediahub

This commit is contained in:
Roardom
2025-03-16 10:54:27 +00:00
parent 1099dfb57a
commit 1e2b4f8cee
4 changed files with 35 additions and 2 deletions

View File

@@ -42,7 +42,12 @@ class CompanySearch extends Component
#[Computed]
final public function companies(): \Illuminate\Pagination\LengthAwarePaginator
{
return Company::withCount('tv', 'movie')
return Company::query()
->withCount([
'movie' => fn ($query) => $query->has('torrents'),
'tv' => fn ($query) => $query->has('torrents'),
])
->where(fn ($query) => $query->whereHas('movieTorrents')->orWhereHas('tvTorrents'))
->when($this->search !== '', fn ($query) => $query->where('name', 'LIKE', '%'.$this->search.'%'))
->oldest('name')
->paginate(30);

View File

@@ -42,7 +42,11 @@ class NetworkSearch extends Component
#[Computed]
final public function networks(): \Illuminate\Pagination\LengthAwarePaginator
{
return Network::withCount('tv')
return Network::query()
->withCount([
'tv' => fn ($query) => $query->has('torrents'),
])
->whereHas('tvTorrents')
->when($this->search !== '', fn ($query) => $query->where('name', 'LIKE', '%'.$this->search.'%'))
->oldest('name')
->paginate(30);

View File

@@ -54,4 +54,20 @@ class Company extends Model
{
return $this->belongsToMany(Tv::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<Torrent, $this>
*/
public function movieTorrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Torrent::class, 'company_movie', 'movie_id', 'company_id', 'id', 'tmdb')->whereRelation('category', 'movie_meta', '=', true);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<Torrent, $this>
*/
public function tvTorrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Torrent::class, 'company_tv', 'tv_id', 'company_id', 'id', 'tmdb')->whereRelation('category', 'tv_meta', '=', true);
}
}

View File

@@ -54,4 +54,12 @@ class Network extends Model
{
return $this->belongsToMany(Movie::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<Torrent, $this>
*/
public function tvTorrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Torrent::class, 'network_tv', 'tv_id', 'network_id', 'id', 'tmdb')->whereRelation('category', 'tv_meta', '=', true);
}
}