Merge branch 'main' of https://homehud.duckdns.org/javier/Nexora
This commit is contained in:
@@ -57,8 +57,12 @@ class UserController extends Controller
|
||||
'end_date' => 'nullable|date|after_or_equal:start_date',
|
||||
'email' => 'required|email|unique:users',
|
||||
'phone' => 'nullable|string|max:20',
|
||||
<<<<<<< HEAD
|
||||
'address' => 'nullable|string|max:255',
|
||||
'profile_photo_path' => 'nullable|string' // Ruta de la imagen subida por Livewire
|
||||
=======
|
||||
'address' => 'nullable|string|max:255'
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
]);
|
||||
|
||||
// Creación del usuario
|
||||
@@ -73,12 +77,20 @@ class UserController extends Controller
|
||||
'address' => $validated['address'],
|
||||
'access_start' => $validated['start_date'],
|
||||
'access_end' => $validated['end_date'],
|
||||
<<<<<<< HEAD
|
||||
'is_active' => true,
|
||||
'profile_photo_path' => $validated['profile_photo_path'] ?? null
|
||||
]);
|
||||
|
||||
if ($request->hasFile('image_path')) {
|
||||
$path = $request->file('image_path')->store('public/photos');
|
||||
=======
|
||||
'is_active' => true
|
||||
]);
|
||||
|
||||
if ($request->hasFile('photo')) {
|
||||
$path = $request->file('photo')->store('public/photos');
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
$user->profile_photo_path = basename($path);
|
||||
$user->save();
|
||||
}
|
||||
@@ -130,11 +142,17 @@ class UserController extends Controller
|
||||
Rule::unique('users')->ignore($user->id)
|
||||
],
|
||||
'phone' => 'nullable|string|max:20',
|
||||
<<<<<<< HEAD
|
||||
'address' => 'nullable|string|max:255',
|
||||
'profile_photo_path' => 'nullable|string', // Añadido para la ruta de la imagen
|
||||
//'is_active' => 'nullable|boolean' // Añadido para el estado activo
|
||||
]);
|
||||
|
||||
=======
|
||||
'address' => 'nullable|string|max:255'
|
||||
]);
|
||||
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
// Preparar datos para actualización
|
||||
$updateData = [
|
||||
'title' => $validated['title'],
|
||||
@@ -146,14 +164,21 @@ class UserController extends Controller
|
||||
'address' => $validated['address'],
|
||||
'access_start' => $validated['start_date'],
|
||||
'access_end' => $validated['end_date'],
|
||||
<<<<<<< HEAD
|
||||
'is_active' => $validated['is_active'] ?? false,
|
||||
'profile_photo_path' => $validated['profile_photo_path'] ?? $user->profile_photo_path
|
||||
];
|
||||
|
||||
=======
|
||||
'is_active' => $request->has('is_active') // Si usas un checkbox
|
||||
];
|
||||
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
// Actualizar contraseña solo si se proporciona
|
||||
if (!empty($validated['password'])) {
|
||||
$updateData['password'] = Hash::make($validated['password']);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
// Eliminar imagen anterior si se está actualizando
|
||||
if (isset($validated['profile_photo_path']) && $user->profile_photo_path) {
|
||||
@@ -171,6 +196,32 @@ class UserController extends Controller
|
||||
return redirect()->back()->withErrors($e->validator)->withInput();
|
||||
|
||||
} catch (QueryException $e) {
|
||||
=======
|
||||
|
||||
if ($request->hasFile('photo')) {
|
||||
// Eliminar foto anterior si existe
|
||||
if ($user->prfile_photo_path) {
|
||||
Storage::delete('public/photos/'.$user->profile_photo_path);
|
||||
}
|
||||
|
||||
$path = $request->file('photo')->store('public/photos');
|
||||
$user->update(['profile_photo_path' => basename($path)]);
|
||||
}
|
||||
|
||||
// Actualizar el usuario
|
||||
$user->update($updateData);
|
||||
|
||||
// Redireccionar con mensaje de éxito
|
||||
return redirect()->route('users.show', $user)
|
||||
->with('success', 'Usuario actualizado exitosamente');
|
||||
|
||||
} catch (ValidationException $e) {
|
||||
// Redireccionar con errores de validación
|
||||
return redirect()->back()->withErrors($e->validator)->withInput();
|
||||
|
||||
} catch (QueryException $e) {
|
||||
// Manejar errores de base de datos
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
$errorCode = $e->errorInfo[1];
|
||||
$errorMessage = 'Error al actualizar el usuario: ';
|
||||
|
||||
@@ -179,11 +230,20 @@ class UserController extends Controller
|
||||
} else {
|
||||
$errorMessage .= 'Error en la base de datos';
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
Log::error("Error actualizando usuario ID {$user->id}: " . $e->getMessage());
|
||||
return redirect()->back()->with('error', $errorMessage)->withInput();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
=======
|
||||
|
||||
Log::error("Error actualizando usuario ID {$user->id}: " . $e->getMessage());
|
||||
return redirect()->back()->with('error', $errorMessage)->withInput();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Manejar otros errores
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
Log::error("Error general actualizando usuario ID {$user->id}: " . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'Ocurrió un error inesperado al actualizar el usuario')->withInput();
|
||||
}
|
||||
@@ -193,13 +253,20 @@ class UserController extends Controller
|
||||
{
|
||||
$previousUser = User::where('id', '<', $user->id)->latest('id')->first();
|
||||
$nextUser = User::where('id', '>', $user->id)->oldest('id')->first();
|
||||
<<<<<<< HEAD
|
||||
$permissionGroups = $this->getPermissionGroups($user);
|
||||
=======
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
|
||||
return view('users.show', [
|
||||
'user' => $user,
|
||||
'previousUser' => $previousUser,
|
||||
'nextUser' => $nextUser,
|
||||
<<<<<<< HEAD
|
||||
'permissionGroups' => $permissionGroups,
|
||||
=======
|
||||
'permissionGroups' => Permission::all()->groupBy('group')
|
||||
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user