Answer the question
In order to leave comments, you need to log in
How to check if such a value exists in a table using laravel validate()?
Good afternoon.
There is an entry in which, among other things, you can change the url. The url must be unique, i.e. There shouldn't be any other posts with this url. When creating a record, everything is easy, I check it like this:
$request->validate([
'slug' => [ 'required', 'unique:posts' ],
]);
Answer the question
In order to leave comments, you need to log in
use Illuminate\Validation\Rule;
Validator::make($data, [
'email' => [
'required',
Rule::unique('users')->ignore($user->id),
],
]);
When editing a record, validation is not so important, since the data in the fields is already present.
Or, in extreme cases, you can not do it for input from url
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question