How to create your own module based on laravel's authentication? - laravel

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.

Related

Laravel + Hyn Tenancy + Spatie Permission, Role Admin in respective Dashboard

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!

How To Make Laravel Admin Approval

im new to laravel. i want to make an admin panel with multiple role, and any role except admin that trying to CRUD, must need Admin approval to implement it. is there any library, or tutorial how to do it, please i need it to learn.
Thanks
You could try the Spatie Permissions package:
https://spatie.be/docs/laravel-permission/v3/introduction
The features you could look at to learn this are Laravel's Gates and Policies, which can be used to restrict access based on criteria.
https://laravel.com/docs/8.x/authorization

Laravel Admin with controller level permissions

what I want to create is Laravel 5.2 Admin and there are around 200 users who will use it with different permissions, so you can say 200 roles with different permissions.
I was planning to eliminate the role part from the picture and create some slug based mechanism, slugs will be related to controller public functions in short routes.
In Admin panel superuser will be able to assign permissions to user on controller functions with slugs.
Is this possible with any existing laravel package currently? If not then what will be the optimal solution you guys propose.
I always use Spatie Package, it is very flexible. You can manage role & permissions or only permissions. It is full of functions that make it easy. Check the documentation.
spatie-laravel-permission

Befor the Auth::check() , Where and How can I set the users access to some functionality or pages

Actually I am beginner in Laravel. By the way, I am using auth and there is a wonderful method, I mean "check" of Auth facade that enable you to protect all routes or controller in that way you want. But Befor this I should say which users can use this route or controller and which users can't.
I seach for it but I didnt find.
Actually I miss a part of this authentication mechanism in Laravel.Please help me about this.
Laravel has a feature called Middlewares where you can check for the user role based on your role_id.
Please see the below link for more clear reference.
https://laravel.com/docs/5.8/middleware
Happy Coding.:)
You need to use middleware for this kind of functionality. Read about middleware in laravel documentation here
Moreover you can use this package to create role for users if you don't want to create roles from scratch. Just add user to a role and use the role name as the middleware.
Have you gone through with ACL stuff in laravel??
Well it will work as per permission which is given by user as per it's role.
For an example Admin has all role so he can access anything. Employee has few rights to access modules so that will define as per need in laravel and that user that do not have access to use some module they'll get some error desgined by developer.
So this all handle through Middleware, and generally that defines by acl
Anything else you want to know?

User and admin role in laravel 5.3

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.

Resources