61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\Hentai;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class Downloads extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public $search;
|
|
|
|
public $order = 'az';
|
|
|
|
public $withTorrents;
|
|
|
|
protected $queryString = [
|
|
'search' => ['except' => '', 'as' => 's'],
|
|
'withTorrents' => ['withTorrents' => '', 'as' => 'withTorrents'],
|
|
'order' => ['except' => '', 'as' => 'order'],
|
|
];
|
|
|
|
public function updatingSearch()
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$orderby = 'slug';
|
|
$orderdirection = 'desc';
|
|
|
|
switch ($this->order) {
|
|
case 'az':
|
|
$orderby = 'slug';
|
|
$orderdirection = 'asc';
|
|
break;
|
|
case 'za':
|
|
$orderby = 'slug';
|
|
$orderdirection = 'desc';
|
|
break;
|
|
default:
|
|
$orderby = 'created_at';
|
|
$orderdirection = 'desc';
|
|
}
|
|
|
|
$hentai = Hentai::with('episodes')
|
|
->when($this->search != '', fn ($query) => $query->whereHas('episodes', fn ($q) => $q->where('title', 'like', '%'.$this->search.'%')->orWhere('title_jpn', 'like', '%'.$this->search.'%')))
|
|
->when($this->withTorrents != '', fn ($query) => $query->whereHas('torrents'))
|
|
->orderBy($orderby, $orderdirection)
|
|
->paginate(10);
|
|
|
|
return view('livewire.downloads', [
|
|
'hentai' => $hentai,
|
|
'query' => $this->search,
|
|
]);
|
|
}
|
|
}
|