简体   繁体   English

如何区分管理员和用户

[英]How to distinguish admin from users

I want to know how should I distinguish admin from others users not by database but by other ways (like sessions). 我想知道如何将管理员与其他用户(不是通过数据库而是通过其他方式(例如会话))区分开来。

I think I should use a middlleware in URLs which contain "admin" or "staff". 我认为我应该在包含“ admin”或“ staff”的URL中使用中间件。 How to route it and how to handle the middelware? 如何路由以及如何处理中间件?

You could use Laravel Permission (or something similar) which lets you manage user permissions and roles in a database. 您可以使用Laravel权限 (或类似的权限 )来管理数据库中的用户权限和角色。

Alternatively, you could create your own system by... 或者,您可以通过以下方式创建自己的系统:

  1. Creating a table for your roles (ie for 'user,' 'admin,' and any other distinction you may want). 为您的角色创建一个表(即“用户”,“管理员”以及您可能需要的其他任何区别)。
  2. Setting the relationship to be 1 to many (if you want users to have multiple permissions) or 1 to 1 (if you want to limit users to a single permission) 将关系设置为1对多(如果您希望用户具有多个权限)或1对1(如果您想将用户限制为单个权限)
  3. Create a middleware to check whether the user has permission after every route call depending on their given role. 创建一个中间件,以根据给定的角色检查用户在每个路由调用之后是否具有权限。 With permission proceed, otherwise you could return an error. 继续进行许可,否则您可能会返回错误。

I would avoid methods without databases if possible for security concerns. 如果出于安全考虑,我会避免没有数据库的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM