From 12e109f82cc2fff7d8be21733b43bb1b6f9ca406 Mon Sep 17 00:00:00 2001 From: Kode Date: Mon, 15 Oct 2018 20:34:21 +0100 Subject: [PATCH] add unique validation for name and don't fail validation when already the owner of data --- app/Http/Controllers/UserController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 8ad29ef2..d76022c1 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -53,7 +53,7 @@ class UserController extends Controller public function store(Request $request) { $validatedData = $request->validate([ - 'name' => 'required|max:255', + 'name' => 'required|max:255|unique:users', 'email' => 'required|email|unique:users', 'password' => 'nullable|confirmed', 'password_confirmation' => 'nullable' @@ -119,8 +119,8 @@ class UserController extends Controller public function update(Request $request, User $user) { $validatedData = $request->validate([ - 'name' => 'required|max:255', - 'email' => 'required|email|unique:users', + 'name' => 'required|max:255|unique:users,name,'.$user->id, + 'email' => 'required|email|unique:users,email,'.$user->id, 'password' => 'nullable|confirmed', 'password_confirmation' => 'nullable' ]);