F
F
fapchat2022-02-05 18:48:36
Laravel
fapchat, 2022-02-05 18:48:36

How to check form field value in laravel for absence in MYSQL table?

The method for checking the input field for existence in the table in laravel is: https://laravel.com/docs/8.x/validation#rule-exists
And I need to understand if the email is in the table, and only then redirect the user to your personal account. Here's how it doesn't work: 'email' => '!exists:users'
However, I want to use laravel's normal validation. For example, in a class for a specific request, write the following code:

return [
            'email' => 'required|email',
            'password' => 'required|confirmed|min:8',
            'email' => '!exists:users'
        ];
Then - pass the request class object to the controller in the method that is associated with the URL that the controller processes.
I don't want to use Validator::make or anything like that. Is it possible to do without all this in my case?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2022-02-05
@sergey-yakovlev

https://laravel.com/docs/8.x/validation#rule-unique

J
JhaoDa, 2022-02-05
@JhaoDa

You can continue reading the section on validation and learn about three types of custom rules with which you can do any kind of validation.

T
tukbaevbr, 2022-02-06
@tukbaevbr

And I need to understand if there is an email in the table, and only then redirect the user to the personal account.

this is not a validation. This is business logic. No need to shove business logic into validation / request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question