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

263
Vistas
MySQL User with Roles, Role specific fields?

I have an application where a User can be a Supplier or a Shop. Now these 2 roles have very different role-specific fields..

Basically, a Shop can make Orders to Suppliers.. So a Shop can make Orders and a Supplier will receive those Orders.

Where would I put these fields for good practice?

  • Add them all on the User class, with nullable types (doesn't seem right!)
  • Create a different class for each Role. So we have a Supplier class with a user_id and Shop class with a user_id, I would have to query these fields using $user->supplier->field or $user->shop->field...

Neither of these seems like thé way to go. Any idea's? Thank you!

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You don't have to stick with a single users table. You can have a Supplier model and a Shop model (with suppliers and shops tables).

Then in the config/auth.php file, you can set up a new auth provider using the Eloquent driver but with a different model. You can then assign those providers to any new guards that you create.

You can read more about authentication and authorisation here: https://laravel.com/docs/5.4/authentication

https://laravel.com/docs/5.4/authorization

Edit

After it was mentioned in the comments about polymorphic relations, I think that would apply better for this type of relationship (multiple types of users, each with own set of fields).

Read more here:

https://laravel.com/docs/5.4/eloquent-relationships#polymorphic-relations

about 4 years ago · Santiago Trujillo Denunciar

0

Can a user have multiple shops or supply multiples? Your second option seems fine.

User hasMany: supplier, shop
- id
- name

Supplier belongsTo, hasOne: user
- id
- user_id
- fields_supplier

Shop belongsTo, hasOne: user
- id
- user_id
- fields_shop

$user->supplier->fields_supplier;
$user->shop->fields_shop;
$supplier->user->name;
$shop->user->name;

-- If you had more info on how you wanted it to work, it would help.

about 4 years ago · Santiago Trujillo Denunciar

0

"Supplier" is a role played by a "Party" ("Individual" or "Organization")

Your store may get a Catalog from a Supplier, and may Request Quotes from them.

Your store creates "Purchase Orders" and sends them to the Supplier, and they send you "Order Responses"

A Supplier is not a user. You could create "User"s for their employees though

Why not just use an existing ERP like Odoo?

about 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