my email unique validation is not working.
From this form, I am sending a user
<form id="edit-form" class="mt-4" action="{{ route('user.update', 1) }}" method="post">
@csrf @method('put')
</form>
It goes here to my web.php
Route::prefix('/user')->group(function () {
Route::put('/update/{user}', [AppHttpControllersUserController::class, 'update'])->name('user.update');
});
Then it comes here in the controller
public function update(UpdateUserRequest $request)
{
dd($request);
}
Which calls this request form:
public function rules(): array
{
return [
'email' => ['nullable', Rule::unique('users', 'email')->ignore($this->id, 'id'), 'email:rfc', 'max:255'],
];
}
Yet everytime, if I send the same email the model already has, it will say that the email is already in use.
2
Answers
Provided that you use this route definition for your update route:
When using the
route
helper, you should pass in an entire user model:You should update the
update
method on yourUserController
:In your
UpdateuserRequest
you will now be able to simply do this:putting here, its not formatting in comment. Its not the actual solution but worked for me inside the controller, try it, if that works it should work in validation request class as well.