From 75b9f4fcbfc3e6b482748480c38e42dfa3cbcb4b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 Apr 2024 15:00:01 +0200 Subject: [PATCH] Add search functionality and display active/inactive subscribers in Admin Dashboard --- app/Livewire/Admin/Index.php | 36 +++++++++++++++++-- .../views/livewire/admin/index.blade.php | 30 +++++++++++----- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/app/Livewire/Admin/Index.php b/app/Livewire/Admin/Index.php index 60bd6f5ea..b72bc8e35 100644 --- a/app/Livewire/Admin/Index.php +++ b/app/Livewire/Admin/Index.php @@ -8,7 +8,31 @@ class Index extends Component { - public $users = []; + public $active_subscribers = []; + public $inactive_subscribers = []; + public $search = ''; + public function submitSearch() { + if ($this->search !== "") { + $this->inactive_subscribers = User::whereDoesntHave('teams', function ($query) { + $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); + })->where(function ($query) { + $query->where('name', 'like', "%{$this->search}%") + ->orWhere('email', 'like', "%{$this->search}%"); + })->get()->filter(function ($user) { + return $user->id !== 0; + }); + $this->active_subscribers = User::whereHas('teams', function ($query) { + $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); + })->where(function ($query) { + $query->where('name', 'like', "%{$this->search}%") + ->orWhere('email', 'like', "%{$this->search}%"); + })->get()->filter(function ($user) { + return $user->id !== 0; + }); + } else { + $this->getSubscribers(); + } + } public function mount() { if (!isCloud()) { @@ -17,7 +41,15 @@ public function mount() if (auth()->user()->id !== 0) { return redirect()->route('dashboard'); } - $this->users = User::whereHas('teams', function ($query) { + $this->getSubscribers(); + } + public function getSubscribers() { + $this->inactive_subscribers = User::whereDoesntHave('teams', function ($query) { + $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); + })->get()->filter(function ($user) { + return $user->id !== 0; + }); + $this->active_subscribers = User::whereHas('teams', function ($query) { $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); })->get()->filter(function ($user) { return $user->id !== 0; diff --git a/resources/views/livewire/admin/index.blade.php b/resources/views/livewire/admin/index.blade.php index 5964097c6..99abdf0e5 100644 --- a/resources/views/livewire/admin/index.blade.php +++ b/resources/views/livewire/admin/index.blade.php @@ -1,17 +1,31 @@

Admin Dashboard

Who am I now?

- {{ auth()->user()->name }} -

Users

+
{{ auth()->user()->name }}
+
+ + Search + +

Active Subscribers

-
- Root -
- @foreach ($users as $user) -
+ @forelse ($active_subscribers as $user) +

{{ $user->name }}

{{ $user->email }}

- @endforeach + @empty +

No active subscribers

+ @endforelse +
+

Inactive Subscribers

+
+ @forelse ($inactive_subscribers as $user) +
+

{{ $user->name }}

+

{{ $user->email }}

+
+ @empty +

No inactive subscribers

+ @endforelse