How to validate if the value of an array, already exist in my database?

I have an array which has a email value, and i want to validate that email if it already exist in my database or not. I try using

static get rules () {
return {
email: ‘unique:users’,

to validate that email but i think it’s not working.
the validation was inside a .forEach () loop and when i try doing that out of the .forEach() it does work…

is there any way i can validate inside the loop?

For that you first need to learn, how to write async loops and that is beyond the scope of the framework.

1 Like

I would like to point out two ways to deal with async / await and loops

  1. Loops that have callback does not support async / await out of box: .map(), .forEach(), .reduce() etc But it works with regular for and while loops
for (let i = 0; i < array.length; i++) {
  await something(array[i])
  1. Use await Promise.all() and array of Promises
let promises = []
array.forEach(element => {
// Next line will wait for all promises to finish
await Promise.all(promises)