Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!