unioil-cms-fe/app/Livewire/UserManagement.php

48 lines
1.3 KiB
PHP

<?php
namespace App\Livewire;
use Livewire\Component;
class UserManagement extends Component
{
public $search = '';
public $users = [];
protected $queryString = ['search'];
// Reset the current page when search is updated
public function updatingSearch()
{
$this->search = $this->search;
}
public function mount()
{
$this->loadUsers();
}
// Get filtered users based on the search input
public function loadUsers()
{
$users = collect(json_decode(file_get_contents(storage_path('app/users.json')), true));
if ($this->search) {
$this->users = $users->filter(function ($user) {
return str_contains(strtolower($user['username']), strtolower($this->search)) ||
str_contains(strtolower($user['first_name']), strtolower($this->search)) ||
str_contains(strtolower($user['last_name']), strtolower($this->search)) ||
str_contains(strtolower($user['email']), strtolower($this->search));
});
} else {
$this->users = $users;
}
}
public function render()
{
return view('livewire.user-management.user-management', [
'users' => $this->users, // Pass filtered users here
]);
}
}