shami003's avatar

What strategy should I follow for role assigning for user in my app?

Hello, I am creating an e-commerce website. The website will have three roles for user (admin, seller, buyer). I want suggestion from you people how I should assign the roles for them? I have a users table and roles table. I created a registration form. Is it will be a good option to put a radion button in registration form so user can select their role at the time of sign up? Your views about this will be helpful.

0 likes
9 replies
MichalOravec's avatar

It depends on you, you can put there radio buttons with seller and buyer, but definitely not admin.

Another option is set it after sign up by administrator. Really it depends on your application.

jlrdw's avatar

I would also suggest you look at some packages on GitHub on how things are done in e-commerce, at least review the code because there's a lot to an e-commerce site.

Also I would highly recommend using a good well maintained package for this instead of Reinventing the wheel.

As you have to deal with payments charges and things of that nature.

shami003's avatar

@jlrdw As I am new to laravel so didn't know about that much. Someone suggested "spatie" for permissions. Don't know how it will work and what things are possible with it.

I will definitely do some search about other packages. Any specific package you recommend?

MThomas's avatar

You might research some of these packages (was the first google search for 'Laravel eCommerce'): https://medium.com/@stenalferd/10-best-laravel-ecommerce-packages-for-your-online-store-1da2743bdda8

As pointed out before, you will learn a lot from other packages. And take a look at several of the series here at laracast, check out this one about building a form, there is a section about roles there too (if i'm not mistaken): https://laracasts.com/series/lets-build-a-forum-with-laravel

jlrdw's avatar

@shami003 I see you are taking video lessons, good. In the from scratch series he has several on authorization also.

And as you learn authentication and authorization (RBAC), keep in mind:

RBAC is at least 3 main steps:

  • A login required (authentication)
  • An authorization implementation to determine what the logged in person with role can or cannot do
  • Protection of URL and parameters, checking that the logged in users id matches the id used in a query

Each application will require unique tweaks in RBAC, no two apps are exactly the same.

I use query scopes for the latter.

shami003's avatar

@jlrdw some stuff is going over my head but I am really enjoying the discussion with you people.

You people are sharing the techniques that will help me a lot. And I will learn from great people like you

Please or to participate in this conversation.