Skip to content

Commit f2820bf

Browse files
committed
Use DB facade instead of Eloquent in IsAdminList
Replaced Eloquent ORM with the DB facade for querying users in the IsAdminList command to reduce overhead. Added a null check for the first user when displaying the super admin details. Also uncommented the User model import in the test case file.
1 parent b43053e commit f2820bf

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Console/Commands/IsAdminList.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Mvd81\LaravelIsAdmin\Console\Commands;
44

5-
use App\Models\User;
5+
use Illuminate\Support\Facades\DB;
66
use Illuminate\Console\Command;
77
use Illuminate\Support\Facades\Schema;
88

@@ -41,15 +41,20 @@ public function handle() {
4141
die;
4242
}
4343

44-
$admins = User::where('is_admin', 1)->get();
44+
$admins = DB::table('users')->where('is_admin', 1)->get();
4545

4646
if (config()->has('is_admin.use_super_admin')) {
47-
$userOne = User::findOrFail(1);
48-
$this->line('Super admin: ' . $userOne->name . '(' . $userOne->id .') | ' . $userOne->email);
47+
48+
$userOne = DB::table('users')->first();
49+
50+
if (!is_null($userOne)) {
51+
$this->line('Super admin: ' . $userOne->name . '(' . $userOne->id . ') | ' . $userOne->email);
52+
}
4953

5054
}
5155

5256
if (!count($admins)) {
57+
5358
$this->line('There are no admin for this project');
5459
}
5560
else {

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Mvd81\LaravelIsAdmin\Test;
44

5-
//use Mvd81\LaravelIsAdmin\Test\Models\User;
5+
use Mvd81\LaravelIsAdmin\Test\Models\User;
66

77
use Illuminate\Database\Schema\Blueprint;
88
use Mvd81\LaravelIsAdmin\Http\Middleware\IsAdmin;

0 commit comments

Comments
 (0)