ฉันมีแบบฟอร์ม laravel เพื่ออัปเดตข้อมูลผู้ใช้ที่มีอยู่ในฐานข้อมูล แต่ถ้าฟิลด์ในแบบฟอร์มนั้นว่างเปล่า ฉันไม่ต้องการให้อัปเดตบันทึกนั้นในฐานข้อมูล ในปัจจุบัน หากฟิลด์ว่างเปล่าและส่งแบบฟอร์มไปแล้ว ระบบจะส่งข้อมูลอินพุตว่างนั้นและลบบันทึกในฐานข้อมูลออก
ด้านล่างนี้เป็นฟังก์ชันในการแก้ไขข้อมูลของผู้ใช้แล้วดำเนินการอัพเดตฐานข้อมูล ขณะนี้ฉันแนบ Request::old('...') ไปกับอีเมล แต่เนื่องจากการตรวจสอบว่าเป็น 'unique:users' จึงทำให้เกิดข้อผิดพลาด 'email is been'
ขอบคุณ,
public function postEdit(Request $request)
{
$this->validate($request, [
'email' => 'unique:users|email|max:255',
'password' => 'min:6',
'confirm_password' => 'same:password',
'about_me' => 'max:500',
]);
Auth::user()->update([
'email' => $request->input('email'),
'password' => bcrypt($request->input('password')),
'confirm_password' => bcrypt($request->input('confirm_password')),
'about_me' => $request->input('about_me'),
]);
return redirect()->route('profile.edit')->with('info', 'You have updated your profile!');
}