|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xetaravel\Http\Livewire\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Database\Query\Builder; |
|
6
|
|
|
use Illuminate\Contracts\View\View; |
|
7
|
|
|
use Illuminate\Pagination\LengthAwarePaginator; |
|
8
|
|
|
use Livewire\Component; |
|
9
|
|
|
use Livewire\WithPagination; |
|
10
|
|
|
use Xetaravel\Http\Livewire\Traits\WithCachedRows; |
|
11
|
|
|
use Xetaravel\Http\Livewire\Traits\WithSorting; |
|
12
|
|
|
use Xetaravel\Http\Livewire\Traits\WithPerPagePagination; |
|
13
|
|
|
use Xetaravel\Models\User; |
|
14
|
|
|
|
|
15
|
|
|
class Users extends Component |
|
16
|
|
|
{ |
|
17
|
|
|
use WithPagination; |
|
|
|
|
|
|
18
|
|
|
use WithSorting; |
|
19
|
|
|
use WithCachedRows; |
|
20
|
|
|
use WithPerPagePagination; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The string to search. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
public string $search = ''; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Used to update in URL the query string. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string[] |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $queryString = [ |
|
35
|
|
|
'sortField' => ['as' => 'f'], |
|
36
|
|
|
'sortDirection' => ['as' => 'd'], |
|
37
|
|
|
'search' => ['except' => '', 'as' => 's'] |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Used to show the delete modal. |
|
42
|
|
|
* |
|
43
|
|
|
* @var bool |
|
44
|
|
|
*/ |
|
45
|
|
|
public bool $showDeleteModal = false; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Number of rows displayed on a page. |
|
49
|
|
|
* @var int |
|
50
|
|
|
*/ |
|
51
|
|
|
public int $perPage = 15; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Function to render the component. |
|
55
|
|
|
* |
|
56
|
|
|
* @return View |
|
57
|
|
|
*/ |
|
58
|
|
|
public function render() |
|
59
|
|
|
{ |
|
60
|
|
|
return view('livewire.admin.users', [ |
|
61
|
|
|
'users' => $this->rows |
|
|
|
|
|
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Create and return the query for the items. |
|
67
|
|
|
* |
|
68
|
|
|
* @return Builder |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getRowsQueryProperty(): Builder |
|
71
|
|
|
{ |
|
72
|
|
|
$search = $this->search; |
|
73
|
|
|
$query = User::query() |
|
74
|
|
|
->where('username', 'LIKE', '%' . $search . '%') |
|
75
|
|
|
->orWhere('email', 'LIKE', '%' . $search . '%') |
|
76
|
|
|
->orWhere('register_ip', 'LIKE', '%' . $search . '%') |
|
77
|
|
|
->orWhere('last_login_ip', 'LIKE', '%' . $search . '%'); |
|
78
|
|
|
|
|
79
|
|
|
return $this->applySorting($query); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Build the query or get it from the cache and paginate it. |
|
84
|
|
|
* |
|
85
|
|
|
* @return LengthAwarePaginator |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getRowsProperty(): LengthAwarePaginator |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->cache(function () { |
|
90
|
|
|
return $this->applyPagination($this->rowsQuery); |
|
|
|
|
|
|
91
|
|
|
}); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|