Laravel Relationships Between Table Values - laravel

This is a rookie question, I know. But I am building an app for my dissertation where I have three types of users. I have added a user role to the standard auth system, and set up middleware and routing based on the role. That all works fine.
But two of my roles are Supervisors (bosses) and DirectReports (employees). I need to tell the app that one supervisor has many employees, and each employee has one supervisor. I wouldn't have any issues with this if I had set up Supervisors and Employees as objects, but right now they're just values entered into a table. Maybe I should have set up a Supervisors table and a Directreports table. I'm just not sure. I'm obviously a hobbiest programmer, and trying to do this for a school project. So I apologize for asking such a basic question.

Related

how to insert skills for users with laravel

I have a (skills) table and (users) table, and I have created (skill_user) table as a pivot,
but my problem is how can I let the user insert any skills he wants, and at the same time it is many to many relationships, which means the user should select the skills which already exist? i cannot understand how can I fix this issue?
There are 3 methods to work with many-to-many relationships:
attach
detach
sync.
I would say sync is more suitable for your case: user selects a list of skills, and you save only these. This also allows to remove skills if user unselected one.

Row Level Security for Power BI

This is kind of an odd situation and I am pretty new to RLS so please forgive me if what I am asking about here might seem a little silly. I am trying to create Row Level Security for a School District. I have a table that has the different schools codes, employee IDs and their position. I have another table that has the employee ID for teachers and their Teacher ID along with the ID if the students they have for the current year with a separate row for each bell period.
I have tried to create a bridge table that contains the Employee ID, Teacher ID as well as the School Codes and connected it with the other two tables.
For testing purposes, I am trying to connect it to the students basic information and set security to see how to give teachers access. I feel like I am almost there but I might be missing something out in here.
Can you please tell me how to go forward from here. Thank you

Laravel - Pivot table with 3 models realtionships Many to Many and One to Many

I want to make authentification in my Laravel project for Users who have Roles and Permissions. Actually That's not a problem to do but Users can create Teams or be invited member of any team and each User in any Team has his ONE Role in the team(in another team the user may have another role). In essense Users must have many Roles but only one role in one particular Team and I can't understand if I create correct DB relationships.
Please check the image with relationships to get more info:
In general:
Users have many Teams, and Teams have many Users(Many to Many)
Teams have many Roles, Roles have many Teams (Many to Many)
Users have many Roles, But only one Role in a Team what relationship should be there?
I'm interested how to do that properly. How to minimize messy code in the future and avoid of need to redesign DB relationships.
Thank you guys so much!
Maybe you do need a polymorphic relationship:
https://laravel.com/docs/master/eloquent-relationships#custom-polymorphic-types
with a morph map.
https://nicolaswidart.com/blog/laravel-52-morph-map

Laravel: Table structure for multiple users types, polymorphic relationships

In my site (api using laravel 5.6 and laravel passport) I have two types of users (Teachers and Students), in the future there will be more. The teacher and student entities are very different, meaning that if I keep them all in one table, the table will be long and many fields will have a null value. Right now I have one Users table with common fields and two other tables (Teachers and Students) to which I have setup a polymorphic relationship from user. My question is if this is a good approach, or if there are other ways to handle this more elegantly?
I would create 1 table for Teachers and 1 table for Students and not use the Users table/model. This way you can keep them completely separate and not worry about adding more types of users in the future. Continually trying to fit new users into your existing Users model, which would be shared, is a headache. I made this same mistake when I started and eventually had to rework the project.
There are plenty of guides for Laravel multi-auth / multi-user online.
Here are a couple to help you get started:
https://medium.com/hello-laravel/multiple-authentication-system-laravel-5-4-ac94c759638a
https://www.codementor.io/okoroaforchukwuemeka/9-tips-to-set-up-multiple-authentication-in-laravel-ak3gtwjvt
Also, there are cases where it makes sense to use the User model for multiple types of users. For example, you may have multiple roles for a user where most/all of the fields are the same (not your scenario). In this case, you can assign a 'role' to each User and the check the roles for actions (e.g. add middleware to prevent roles from accessing various routes). Here is an example:
https://medium.com/#ezp127/laravel-5-4-native-user-authentication-role-authorization-3dbae4049c8a
Since you said the teacher and student entities are very different, you should keep them separate.

Implementing a mini social graph

I have an application where users of the application can have many contacts ( other users of the application ) related to them. I would like to maintain a relation between a single user and its set of contacts. At any given point of time, I do NOT need to know anything more than the direct set of contacts for a particular user, i.e, contacts of contact of a particular user is not of relevance in this application.
Any suggestion on how to organise this data within the database? Please note that the number of users could go up really high.
Just to add some extra info, the database I am using right now is Mongodb and language being used is Ruby.
The only model right now before thinking of building all these relations is the Users model which stores details of each user registered onto the application. Now as I mentioned above, I need to built the specified relation between the user and its set of contacts. Any help would be highly appreciated.

Resources