Laravel Roles – Managing Complex Roles, Permissions, and Hierarchical Groups in Laravel

laravelpermissionsproject-structureroles

I'm currently in the planning phase / feasability study of a rather big web application which is meant to be implemented using Laravel.
My own experience on the matter is rather limited but I'd like to take the opportunity to further my skills and, if successful, release the basis of the code under MIT license for anyone to use.

The task at hand (sorry for the essay but it's rather complex):

I'm working for a company with a rather complex customer and service structure: We offer multiple services, ranging from risk assessment to education (online and on-site) in workplace safety, security data sheets for products, environmental questions, data protection etc. and want to create a platform that allows us to manage our customer and service structure while also giving our customers access to these services online, including API support.
Customers may have entirely different company hierarchies, ranging from a small company of 10 employees that just distinguishes between regular employees and management to companies with thousands of employees with complex hierarchies including multiple branches, departments, sites and project management.

Some of our services are specific to sites, some to departments, some to branches, some to projects (e.g. a construction project) and/or to the whole company. We wish to have different access levels for different employees of the customers and the optional ability for customer admins to manage their own users/permissions.

The idea was to create a global management platform which manages the whole customer, user and permission structure with the individual services being split up into different apps which are included in the global platform but can individually be assigned to each customer with the ability to assign certain roles for users and groups to each app, also users can have multiple group memberships and different roles in different groups.
These apps not only include our services, but also basic functionality like user and group management.
The management of the platform should be separate from the user part, meaning our employees should have access via an administrative dashboard while also having the ability to assign a certain customer to a certain employee of ours with the permission to manage one or more specific service for this customer.

Here is the idea for a database structure I had:
Database structure
The individual services/apps will have their own respective tables except for the ones which are there for global management functionality like user management.

The questions I have:

  1. Is this even feasible to do with Laravel? If not, what are the alternatives?
  2. Is my database structure ok or compeletely stupid for the task at hand?
  3. Which are the Laravel plugins I should look into?
  4. Any other directions, e.g. folder structure within the laravel project folder etc.?

Best Answer

First off, i'd like to clarify that i'm fairly new in Laravel myself and that there are far more experienced people in terms of Software Engineering. So please take my answer with a grain of salt. I am however working on a big application myself for the last 2 months using Laravel. I will also try to answer your question 'as is' which seems to be focused on Laravel.

Is this even feasible to do with Laravel? If not, what are the alternatives?

From your question i cannot see why this would not be possible using Laravel.

Is my database structure ok or compeletely stupid for the task at hand?

As it is right now, this is unclear to me. Make sure you can solve every possible problem with your DB structure. In the process of designing, you have to ask youself many tough questions.

  • What if people leave?
  • What if a company fuses / takes a on a completely different structure?
  • What if people get a completely different role? But have done important tasks for that organisation in the past?
  • Could i add things without getting into trouble?

And countless more.

Which are the Laravel plugins I should look into?

Well i can recommend a general direction.

Remember that Laravel already has done the bulk of the work for you. So when you have come up with a general solution, make sure you always check the docs. I cannot tell you how much time this saved me.

Any other directions, e.g. folder structure within the laravel project folder etc.?

Yes! You will most likely need versioning of some sort (especially within your API. ) This will save you alot of trouble when trying to expand your application. You can achieve this easily using Route groups and prefixing.

For example, create a Api route group using v1. Now every route within this group will begin with /api/v1/. Now when you have to change your api, you won't agitate everyone using your api.

While your application is growing and changing, make sure you take a closer look at Eloquent's resources. This will allow you to stay flexible, and not break your application when you have to make changes to your database.

Again, i know there is alot more to your question. But i tried to take a look at your post from the perspective of utilities offered by Laravel.