Init
This commit is contained in:
60
app/Livewire/Downloads.php
Normal file
60
app/Livewire/Downloads.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user