Skip to content

Commit

Permalink
Option To Hiding Trashed Data
Browse files Browse the repository at this point in the history
  • Loading branch information
SupianIDz committed Feb 28, 2023
1 parent 370983d commit 5a708a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions config/impersonate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
*/
'model' => config('auth.providers.users.model'),

/*
|--------------------------------------------------------------------------
| Show Trashed Users
|--------------------------------------------------------------------------
|
| If you are using the SoftDeletes trait on your User model, you can
| set this to true to show trashed users in the select dropdown.
|
*/
'trashed' => true,

/*
|--------------------------------------------------------------------------
| Authentication Guards
Expand Down
9 changes: 7 additions & 2 deletions src/ImpersonateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Octopy\Impersonate;

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
Expand Down Expand Up @@ -38,11 +39,15 @@ public function findUser(int|string $impersonator) : User
public function getUsers(string $search = null) : Collection
{
// TODO : Allow to search users by raw query.

$query = $this->model->newModelQuery()->limit(config(
$query = $this->model->newQuery()->limit(config(
'impersonate.interface.limit', 10
));

// If trashed is true, we will add a withTrashed clause to the query
if (config('impersonate.trashed', false) && in_array(SoftDeletes::class, class_uses_recursive($this->model))) {
$query = $query->withTrashed();
}

// If search is not null, we will add a where clause to the query
if ($search) {
foreach ($this->getColumns() as $column) {
Expand Down

0 comments on commit 5a708a8

Please sign in to comment.