In my laravel project, I want some admin and user role. I want to make user login in different routes after login. And also for admin also. How should I do it?
You should first make 3 table in your database; user, role and user_role. user_role table has many to many relationship. Then you will make a middleware that checks your role checks when login. In your route, you use that middleware in login's post.
See details about middle ware in laravel 5.3 documentation.
https://www.laravel.com/docs/5.3/middleware
You can try laravel 5.3 boilerplate. It comes with a full featured access control system out of the box with an easy to learn API and is built on a Twitter Bootstrap foundation with a front and backend architecture.
Related
In my system, there are tow types of users.
Admin.
Regular.
For admin I am using Laravel backpack. But, I also want the backpack's features for non admin panel also.
What's the way?
Usually people use Roles/Permissions to handle that.
There is a Backpack addon that will give you a kick start with cruds for user/permission/role using the Spatie Laravel Permission under the hood: https://github.com/Laravel-Backpack/PermissionManager
Then you can show some bits of your app to some users, hide some fields/columns from others etc.
Just remember that users will be authenticating using backpack guard, so you should use backpack_user()->hasRole(), or see the advanced configuration of the package in ReadMe.
Cheers
I have two table users and role and I need to log in using Laravel fortify only if user role is admin or showing error. I tried to do that using middelware, but i need to add the condition: If the user is not admin, he cannot log in.
You can read at laravel docs:
https://laravel.com/docs/8.x/fortify#laravel-fortify-and-laravel-sanctum
Some developers become confused regarding the difference between Laravel Sanctum and Laravel Fortify
And:
If you are attempting to manually build the authentication layer for an
application that offers an API or serves as the backend for a single-page
application, it is entirely possible that you will utilize both Laravel Fortify
(for user registration, password reset, etc.) and Laravel Sanctum (API token
management, session authentication).
Then you want to check role of user, you should use Laravel Sanctum
good morning to everyone, I will comment on the situation to see if you can give me an idea ...
I am using Hyn Tenancy (Saas) and Spatie Permissions
Currently I have the whole system working without problems and it is as follows:
Users can log in to domain.com or sub1.domain.com or sub2.domain.com and from either enter their account and the session is shared.
and a general dashboard where it shows a history of your purchases in any subdomain.
so far so good ...
Now create the dashboard for the admins ... which is accessed from sub1.domain.com/admin
the problem I have is that everyone who is admin can enter but I only need admin1 to enter sub1.domain.com/admin
admin2 to sub2.domanin.com/admin
Any can help me plz?
It's look like you can't share any code with community.
So with experience in laravel permission and your senario as I know you want each subdomain wit an admin have only access to his/her subdomain admin area.
you should create a new gate or middleware or in your gate for admins define an if to check if the user is a member of subdomain?
in laravel permission only administrators explited from other users and you should define new gate or middleware and add it to admin route definition.
Solved, i use a uuid from subdomain... and compare with a user uuid... if correct it show the forms, else search the uuid in a subdomain and redirect it to our domain.
Thanks you!
I have requirement of user login in frontend and also i need to make admin panel in laravel, i have create custom user table for frontend user because its have multiple other fields, in this case if i use laravel php artisan make:auth then it will create laravel login that i can redirect to different route(different admin folder in views) but if i use laravel default login and add frontend user custom fields in db table then how can i use this direction? My main question is, i need to use laravel make:auth db table for front end user and administrator user with different role or i need to make two different tables for both admin and frontuser login?
You can use the package below to do this.
The following package contains the Role&Permission - registration and login.
If your problem is not resolved, I can help you more.
I am new to laravel and currently i am learning and experimenting on my old php based mini-project conecpt ,i have successfully created the user registration and user login with some features for users,but i am confused how do i create a admin module and provide admin privilege's along with one more sub module (moderator).
I have completed website module,it works fine but i am confused how do i give the following functionalities.
how do i add admin module
admin can access user information
only admin can add moderator
any suggestions would be helpful,
Thank you.
I think what you are trying to do is make some routes only accessible by an admin or moderator?
Make a custom middleware so only if a user has a sufficient role level they can acces the given route.
https://laravel.com/docs/5.6/middleware#defining-middleware
You could have a moderator middleware that checks if a user has role 1 or higher, and a admin middleware that checks if a user has role 2.
i hope this is somewhat what you are searching for.