Answer the question
In order to leave comments, you need to log in
How to describe the validation rule for unique fields when updating data?
There is a form request StoreEmployee:
With the help of which I validate the data when creating a record and updating, when creating everything is fine, but when updating, the uniqueness rule is constantly triggered. How to describe the validation rule for unique fields on update?
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreEmployee extends FormRequest
{
public function rules()
{
return [
'fname' => 'required|alpha|string|max:255',
'lname' => 'required|alpha|string|max:255',
'pname' => 'required|alpha|string|max:255',
'avatar' => 'required|image',
'birth_date' => 'required|date',
'login' => 'required|unique:employees',
'password' => 'nullable|min:10|alpha_dash',
'role' => 'required',
'phones' => 'required|array',
'phones.*.phone' => 'required|unique:phones',
'phones.*.is_personal' => 'nullable|boolean',
'phones.*.is_work' => 'nullable|boolean',
'emails' => 'required|array',
'emails.*.email' => 'required|email|unique:emails',
];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question