validate([ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($user->id)], 'avatar' => ['nullable', 'image', 'max:2048', 'mimes:jpeg,png,jpg,gif,webp'], // Max 2MB 'company' => ['nullable', 'string', 'max:255'], 'website' => ['nullable', 'url', 'max:255'], 'whatsapp' => ['nullable', 'string', 'max:20', 'regex:/^[\d\s\(\)\+\-]{10,20}$/'], 'password' => ['nullable', 'string', 'min:8', 'confirmed'], ], [ 'avatar.mimes' => 'O avatar deve ser do tipo: JPEG, PNG, JPG, GIF ou WebP.', 'website.url' => 'O formato do site é inválido.', 'whatsapp.regex' => 'O formato do WhatsApp é inválido.', ]); $data = $request->except(['password', 'avatar']); if ($request->filled('password')) { $data['password'] = Hash::make($request->password); } if ($request->hasFile('avatar')) { // Remove avatar antigo se existir if ($user->avatar) { Storage::disk('public')->delete($user->avatar); } $data['avatar'] = $request->file('avatar')->store('avatars', 'public'); } $user->update($data); return redirect()->route('profile.edit')->with('success', 'Perfil atualizado com sucesso!'); } /** * Show user preferences. */ public function preferences() { $user = Auth::user(); $preferences = $user->preferences ?? [ 'notifications_email' => true, 'notifications_system' => true, 'notifications_new_users' => true, 'notifications_page_actions' => true, 'notifications_gallery_actions' => true, 'notifications_product_actions' => true, 'theme' => 'light' ]; return view('profile.preferences', compact('user', 'preferences')); } /** * Update user preferences. */ public function updatePreferences(Request $request) { /** @var \App\Models\User $user */ $user = Auth::user(); $user->update([ 'preferences' => [ 'notifications_email' => $request->has('notifications_email'), 'notifications_system' => $request->has('notifications_system'), 'notifications_new_users' => $request->has('notifications_new_users'), 'notifications_page_actions' => $request->has('notifications_page_actions'), 'notifications_gallery_actions' => $request->has('notifications_gallery_actions'), 'notifications_product_actions' => $request->has('notifications_product_actions'), 'theme' => $request->theme ?? 'light' ] ]); if ($user->user_type === 'Admin') { Setting::set('site_maintenance', $request->has('site_maintenance') ? 'on' : 'off', 'general'); Setting::set('whatsapp_floating_button', $request->has('whatsapp_floating_button') ? 'on' : 'off', 'general'); Setting::set('public_registration', $request->has('public_registration') ? 'on' : 'off', 'general'); // Salvar configurações de horário do WhatsApp Setting::set('whatsapp_start_time', $request->whatsapp_start_time ?? '08:00', 'general'); Setting::set('whatsapp_end_time', $request->whatsapp_end_time ?? '18:00', 'general'); Setting::set('whatsapp_lunch_start', $request->whatsapp_lunch_start, 'general'); Setting::set('whatsapp_lunch_end', $request->whatsapp_lunch_end, 'general'); } return redirect()->route('profile.preferences')->with('success', 'Preferências atualizadas com sucesso!'); } }