Skip to content
Advertisement

how to create an alert if the same data has been added using laravel?

I made an add user feature, but if I add the same data there will be a problem, I want to limit the duplicate data, how to create a warning if the same data has been added?

Source Code UserController

JavaScript

Screenshot Error Image

Advertisement

Answer

There are two ways to do it. First is to add ‘unique’ to your validation. For example:

JavaScript

or you can manually check if the user already exists by adding an if statement like this:

JavaScript

Reference for the first example: Laravel unique validation

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement