validate([ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed', 'role_type' => 'doctor', // Присваиваем роль ]); // Создание пользователя $user = User::create([ 'name' => $validated['name'], 'email' => $validated['email'], 'password' => bcrypt($validated['password']), 'role_type' => 'doctor' ]); // Назначение роли "doctor" $user->assignRole('doctor'); return response()->json(['message' => 'Doctor registered successfully']); } public function registerPatient(Request $request) { // Проверяем, что пользователь - доктор if (!auth()->user()->hasRole('doctor')) { return response()->json(['message' => 'Unauthorized'], 403); } // Валидация $validated = $request->validate([ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed', ]); // Создаем пациента $patient = User::create([ 'name' => $validated['name'], 'email' => $validated['email'], 'password' => bcrypt($validated['password']), 'role_type' => 'patient', // Присваиваем роль 'doctor_id' => auth()->user()->id, // Сохраняем ID текущего доктора ]); // Назначаем роль "patient" $patient->assignRole('patient'); return response()->json(['message' => 'Patient registered successfully']); } }