Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

347
Vistas
Laravel Unique Validation Based on Multiple Column Data Value

Image of Database

In this scenario , My Phone number will be unique based on my domain_id. Phone number can be multiple in phone columns but its obvioulsy would be depend on domain_id column.

Example: 01303062727 This Numbers are two times is phone column but they have different domain_id value.

How can be validate this rules ?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

here you can take advantage of unique rule that laravel provides. your code would be something like this :

'phone_number' => Rule::unique('users')->where(function ($query) {
    return $query->where('domain_id', $domain_id);
})

obviously you may pass $domain_id variable along with your inputs or any other way you want . this code will scopes the query to make rule of uniqueness only toward records that have domain_id of a specific value. so repeated number will be allowed but for different domain ids

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda