nothing
This commit is contained in:
19
app/Http/Controllers/Web/Admin/AdminController.php
Normal file
19
app/Http/Controllers/Web/Admin/AdminController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Admin/Index',
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
100
app/Http/Controllers/Web/Admin/UserController.php
Normal file
100
app/Http/Controllers/Web/Admin/UserController.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Department;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDepartment;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$users = User::with(['roles', 'department'])->get()->map(function ($user) {
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'login' => $user->login,
|
||||
'is_active' => $user->is_active,
|
||||
'created_at' => $user->created_at->format('d.m.Y H:i:s'),
|
||||
'updated_at' => $user->updated_at->format('d.m.Y H:i:s'),
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('Admin/Users/Index',
|
||||
[
|
||||
'users' => $users,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$rolesData = Role::all()->map(function ($role) {
|
||||
return [
|
||||
'role_id' => $role->role_id,
|
||||
'name' => $role->name,
|
||||
];
|
||||
});
|
||||
|
||||
$departmentData = Department::all()->map(function (Department $department) {
|
||||
return [
|
||||
'department_id' => $department->department_id,
|
||||
'name_full' => $department->name_full,
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('Admin/Users/Create', [
|
||||
'departments' => $departmentData,
|
||||
'roles' => $rolesData,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string',
|
||||
'login' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
'is_active' => 'required|boolean',
|
||||
]);
|
||||
|
||||
dd($validated);
|
||||
}
|
||||
|
||||
public function show(User $user, Request $request)
|
||||
{
|
||||
$userData = [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'login' => $user->login,
|
||||
'is_active' => $user->is_active,
|
||||
'created_at' => $user->created_at->format('d.m.Y H:i:s'),
|
||||
'updated_at' => $user->updated_at->format('d.m.Y H:i:s'),
|
||||
];
|
||||
|
||||
$rolesData = $user->roles->map(function ($role) {
|
||||
return [
|
||||
'role_id' => $role->role_id,
|
||||
'name' => $role->name,
|
||||
];
|
||||
});
|
||||
|
||||
$departmentData = $user->departments->map(function (UserDepartment $userDepartment) {
|
||||
return [
|
||||
'department_id' => $userDepartment->department->department_id,
|
||||
'name_full' => $userDepartment->department->name_full,
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('Admin/Users/User', [
|
||||
'userData' => $userData,
|
||||
'roles' => $rolesData,
|
||||
'departments' => $departmentData,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user