Files
portal-api/app/Http/Livewire/MyService.php
T
2025-07-24 16:18:27 +07:00

69 lines
1.7 KiB
PHP

<?php
namespace App\Http\Livewire;
use App\Models\Invoice;
use App\Repositories\Invoice\InvoiceRepositoryInterface;
use Livewire\Component;
use Livewire\WithoutUrlPagination;
use Livewire\WithPagination;
class MyService extends Component
{
use WithPagination, WithoutUrlPagination;
public int|string $status = 'full';
public $type = '';
public $search = '';
protected $invoiceRepository;
public function mount(InvoiceRepositoryInterface $invoiceRepository)
{
$this->invoiceRepository = $invoiceRepository;
}
public function updatedSearch()
{
$this->resetPage();
}
public function updatedStatus()
{
$this->resetPage();
}
public function updatedType()
{
$this->resetPage();
}
public function render()
{
$query = Invoice::where('customer_id', customer()->id)
->with([
'invoiceItem.hosting',
'invoiceItem.vps',
'invoiceItem.os.osGroup',
'invoiceItem.addons.addonItems'
]);
// Filter by type if specified
if (!empty($this->type)) {
$query->whereHas('invoiceItem', function($q) {
$q->where('product_type', $this->type);
});
}
// Filter by server_name search if specified
if (!empty($this->search)) {
$query->whereHas('invoiceItem', function($q) {
$q->where('server_name', 'like', '%' . $this->search . '%');
});
}
return view('livewire.my-service', [
'services' => $query->orderBy('created_at', 'desc')->paginate(10)
]);
}
}