Add first pass of the web interface: Sites index + detail, via Livewire
Home page is now a Livewire-powered, searchable/paginated Site list (search by domain) instead of the stock Laravel welcome page. Clicking a site goes to a plain controller-rendered detail page listing its pages. Shared layout at resources/views/components/layouts/app.blade.php.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Sites;
|
||||
|
||||
use App\Models\Site;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
#[Layout('components.layouts.app')]
|
||||
class Index extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
#[Url(as: 'q', history: true)]
|
||||
public string $search = '';
|
||||
|
||||
public function updatingSearch(): void
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$sites = Site::query()
|
||||
->withCount('pages')
|
||||
->when(
|
||||
$this->search !== '',
|
||||
fn ($query) => $query->where('domain', 'like', '%'.$this->search.'%')
|
||||
)
|
||||
->orderBy('domain')
|
||||
->paginate(25);
|
||||
|
||||
return view('livewire.sites.index', ['sites' => $sites]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user