59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Pages\Links;
|
|
|
|
use App\Domains\Link\Actions\DeleteLink;
|
|
use App\Domains\Link\Models\Link;
|
|
use Illuminate\View\View;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class Index extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public string $search = '';
|
|
|
|
public string $statusFilter = '';
|
|
|
|
public function updatingSearch(): void
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function updatingStatusFilter(): void
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function deleteLink(int $id, DeleteLink $action): void
|
|
{
|
|
$workspace = app('current_workspace');
|
|
$link = Link::where('id', $id)
|
|
->where('workspace_id', $workspace->id)
|
|
->firstOrFail();
|
|
|
|
$this->authorize('update', $workspace);
|
|
$action->handle($link);
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
$workspace = app('current_workspace');
|
|
|
|
$links = Link::where('workspace_id', $workspace->id)
|
|
->when($this->search, fn ($q) => $q->where(function ($q) {
|
|
$q->where('title', 'like', "%{$this->search}%")
|
|
->orWhere('slug', 'like', "%{$this->search}%")
|
|
->orWhere('target_url', 'like', "%{$this->search}%");
|
|
}))
|
|
->when($this->statusFilter, fn ($q) => $q->where('status', $this->statusFilter))
|
|
->latest()
|
|
->paginate(20);
|
|
|
|
return view('livewire.pages.links.index', compact('links'))
|
|
->layout('layouts.nimuli-app', ['title' => 'Links']);
|
|
}
|
|
}
|