Home > OS >  How can I make a single validation rule in Laravel that meets two conditions?
How can I make a single validation rule in Laravel that meets two conditions?

Time:02-04

I have a question in Laravel. How can I make a single validation rule in Laravel that meets two conditions? The logic would be like this in the database:

"users.document_usu is unique and users.rol_usu=2"

How could I modify this rule so that it does the same "unique:users,document_usu"

thank you very much for your attention.

CodePudding user response:

You can use Rule class

    'document_usu' => ['required', Rule::unique('users')->where(function ($query) use ($request) {
        return $query->where('rol_usu', 2); 
     })],
  •  Tags:  
  • Related