Answer the question
In order to leave comments, you need to log in
How to check for uniqueness when updating a table?
When creating a table, checking for the uniqueness of the desired columns is clear. But how to logically check on update? For example, there are fields:
--------------------
name: Name
sort: 500
section: 12
------------------ - And in the sections
table , the name field must be unique.
When updating, for example, I only change the sort field. And now, when checking for uniqueness, there will be an error, since the name field already exists in itself ... I
check through validation:
$validator = Validator::make($request->all(), [
'sect_name' => 'required|unique:sections,name|max:255',
]);
Answer the question
In order to leave comments, you need to log in
unique has many parameters, including the id of the record to be ignored during validation, check the documentation for the order of the parameters.
In 5.2, this is the third parameter.
The following syntax is available in the latest 5.3.*:
Documentation: https://laravel.com/docs/5.3/validation#rule-unique
Section Forcing A Unique Rule To Ignore A Given ID
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question