Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda