User and Admin relationship in spring boot - spring-boot

Roles tables only two roles Admin and User only. ( Static table)
Admin
User
User tables - whenever user register the page, it will automatically comes (2- User (Roles table)
Ex.
Si.no . Name address email rollid
1 xxx yyyy zzzz 2-(Roles table ) Users only registered so Users no 2 come from Roles table
Doubt?
What is the relationship between them
ManyTomany or Onetoone
. Many users have many roles. But my case one user object have one role only.. Which one is correct? Then how can insert value 2 to user table whenever user register the page. Please advice
Two tables is enough no need for third table

Related

Laravel multi-auth different table for admin and user but one login page

Is it possible to have two different tables for users and admin but one login page? I already used middleware and Spatie permission, but I need them to separate because some info doesn't match if they are together in one table.
For example:
Admin needs name, employee number. At the same time, users need a name, address, student number, etc.
I need suggestions on how to do that to study it.

One model, one table different user types and different controllers, how to handle policies?

I have one model user and one table against that model users I have different roles for user as patient, hospital and so on, each user have different fields and values to enter during registration so I have created different routes and controllers for different roles.
Now I'm facing problem during authorization process how I can authorize. I have only one model user so I can create only one policy called UserPolicy and use the $this->authorize method in the UserController.
I have also other controllers as PatientController, HospitalController which all bound to the one table and model called user and fetching the record only based on the user type. Now how can I create the policies for them and use the $this->authorize method in the Hospital, Patient controllers?
you are using the same table and you require different data from each kind if user ?
anyway if that the situation , you can create a type field in the users table , then create 2 middlewares , in your middleware check the type of the user then throw an exception or make him pass

Laravel 5.1 Sync user to other users

I build a Laravel app.
In table users I have 2 kinds of users - one user is restaurants and another user is restaurant stuff.
What I exactly need?
I want to sync user (res stuff) to user (restaurant). Is that possible or I need to move the restaurant to the other table and then sync?
I'm looking just for the idea and is that possible?
What is the difference between the user in the same table is admin field - res users have value '999' at admin column and res stuff has value '1' at admin column.

Fetch User detail with his role in laravel 5.4

My Application have below setup
Users table:
id
roleid
firstname
email
password
Roles table:
id
userid
rolename
There will be total 4 fixed roles and those will be assigned to users.
Now i want related role name when i do login with user.So in laravel eloquent model how can i define the relationships and how can i fetch and display?
I am new to laravel 5.4
If your relation between user and roles is One To Many
Have a read on below link. You'll get the idea.
https://laravel.com/docs/5.4/eloquent-relationships#one-to-many

Complicated Eloquent Relationships

I have a many-to-many relationship, users and roles, which I have worked out just fine. However, I have another table I would like to relate as well, called leads. A user and that user's role can be assigned to a lead.
So for example, I've created a Role and let's call it 'Manager'. Now, when I am managing my Users, I'd need to be able to assign different users to different roles which will be a many-to-many relationship (a role can have many users, a user can have many roles). So I will assign the role of 'Manager' to User A.
Now, when I am modifying my leads, I'd like to be able to assign a role_user to my lead (In my example, I'd like to assign a user to that lead), but I'd first need to assign a role to that Lead (Manager), and then be able to assign a user that is of that role to that lead.
Currently, I've got a many-to-many relationship setup for users and roles, using the pivot table name role_user. I've then got a many-to-many relationship setup on that pivot table, role_user, and leads, using another pivot table named lead_role_user.
Models + Controller - http://paste.laravel.com/D6h
My error: Call to undefined method Illuminate\Database\Query\Builder::roles()
It feels as though I am making this much more difficult than it should be.

Resources