I ran into a problem the other day when I was trying to create a page where an admin could update user details in a dashboard area of an app. Basically I needed the user to be able to update an email address and name field. What I was finding was that the email address would update no problem but the name wouldn’t. Here is what I had set up:
The Edit Form
The Update Method In The Users Controller
The User Form Request
It was Jason Varga (my Laravel hero and Wilderborn colleague) who pointed out that there is this additional requirement in the Laravel docs. Basically if you need to update other fields along with a unique field then you need to tell the unique rule to ignore the user’s ID, you may pass the ID as the third parameter. You will see in the example below that I grab the user ID using Route::current()->getParameter('users') then pass that into the email rule as the $user_id variable.