40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\UpdateUserAdminStatusRequest;
|
|
use App\Models\User;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Arr;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class UserManagementController extends Controller
|
|
{
|
|
public function index(): Response
|
|
{
|
|
return Inertia::render('admin/users/Index', [
|
|
'status' => session('status'),
|
|
'users' => User::query()
|
|
->orderByDesc('is_admin')
|
|
->orderBy('name')
|
|
->get(),
|
|
]);
|
|
}
|
|
|
|
public function update(UpdateUserAdminStatusRequest $request, User $user): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
|
|
$user->is_admin = $validated['is_admin'];
|
|
$user->save();
|
|
|
|
$status = $user->is_admin
|
|
? "{$user->name} now has admin access."
|
|
: "{$user->name} no longer has admin access.";
|
|
|
|
return to_route('admin.users.index')->with('status', $status);
|
|
}
|
|
}
|