51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\MemberManagement;
|
|
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class CardMemberList extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public $filters = [
|
|
'status' => '',
|
|
];
|
|
|
|
public $members = [];
|
|
|
|
public function mount()
|
|
{
|
|
$this->fetchMembers();
|
|
}
|
|
|
|
public function fetchMembers()
|
|
{
|
|
$url = 'https://api.example.com/member' . ($this->filters['status'] ? '?status=' . ($this->filters['status'] === 'active' ? 'active' : 'inactive') : '');
|
|
|
|
$this->members = $this->fetchFromApi($url);
|
|
}
|
|
|
|
public function updatedFilters()
|
|
{
|
|
$this->resetPage();
|
|
$this->fetchMembers();
|
|
}
|
|
|
|
private function fetchFromApi($url)
|
|
{
|
|
try {
|
|
$response = \Http::get($url);
|
|
return $response->json()['data'] ?? [];
|
|
} catch (\Exception $e) {
|
|
session()->flash('error', 'Failed to load members: ' . $e->getMessage());
|
|
return [];
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.card-member-list');
|
|
}
|
|
} |