cms-laravel/app/Livewire/TopUp/TopUpList.php

56 lines
1.5 KiB
PHP

<?php
namespace App\Livewire\TopUp;
use Livewire\Component;
use App\Services\ApiService;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Log;
class TopUpList extends Component
{
public $topUps = [];
public $loading = false;
public $updating = false;
protected $apiService;
public function boot(ApiService $apiService)
{
$this->apiService = $apiService;
}
public function mount()
{
// Check role-based access
$userInfo = Session::get('userInfo');
if (!$userInfo || $userInfo['role'] != 1) {
return redirect()->route('404');
}
$this->loadTopUps();
}
public function loadTopUps()
{
$this->loading = true;
try {
$response = $this->apiService->get('topUp?page=1&page_size=10&_sort_by=create_dt&_sort_order=desc');
if ($response && isset($response['data'])) {
$this->topUps = $response['data'];
Log::info('Top-up list loaded', ['source' => 'TopUpList']);
}
} catch (\Exception $e) {
Session::flash('error', 'Failed to load top-ups: ' . $e->getMessage());
Log::error('Failed to load top-up list', ['error' => $e->getMessage(), 'source' => 'TopUpList']);
} finally {
$this->loading = false;
}
}
public function render()
{
return view('livewire.top-up.top-up-list')->layout('layouts.app', ['title' => 'Top-Up']);
}
}