简体   繁体   English

Laravel 9 背包 5.x laravel-permission 如何配置 CheckIfAdmin.php 使用户无法访问背包管理前端

[英]Laravel 9 backpack 5.x laravel-permission how to configure CheckIfAdmin.php so users can't access backpack admin front-end

I'm new to Laravel and all that, and currently working on a little project.我是 Laravel 的新手,目前正在做一个小项目。 The task is to separate admins and users.任务是将管理员和用户分开。 So I want, just my admins, to access example.com/admin/dashboard.因此,我只想让我的管理员访问 example.com/admin/dashboard。 I read through some docs and came across this:我阅读了一些文档并遇到了这个:

"2) Middleware to app/Http/Middleware/CheckIfAdmin.php "2) 中间件到app/Http/Middleware/CheckIfAdmin.php

This middleware is used to test if users have access to admin panel pages.此中间件用于测试用户是否有权访问管理面板页面。 You can (and should customize it) if you have both users and admins in your app." in: https://backpackforlaravel.com/docs/5.x/base-about如果您的应用程序中有用户和管理员,您可以(并且应该自定义它)。”在: https ://backpackforlaravel.com/docs/5.x/base-about

But since I'm new to all this, I don't know how to "customize" "app/Http/Middleware/CheckIfAdmin.php".但由于我对这一切都不熟悉,我不知道如何“自定义”“app/Http/Middleware/CheckIfAdmin.php”。

Plus, do I need a second table for my admins, or can I just add a new column, with the name is_admin for example, to my "users" table?另外,我是否需要为我的管理员创建第二张表,或者我可以添加一个名为 is_admin 的新列到我的“用户”表中吗? Can I do it with just app/Models/User.php, or do I need a separate app/Models/admin.php?我可以只使用 app/Models/User.php,还是需要单独的 app/Models/admin.php? Also, which guard do I have to use in "config/backpack/base.php", since when I use "null" instead of "backpack" or "web", I get an error saying:"guard [null] is not defined".另外,我必须在“config/backpack/base.php”中使用哪个保护,因为当我使用“null”而不是“backpack”或“web”时,我收到一条错误消息:“guard [null] is not定义”。

As you can see, I'm pretty lost here, but I hope that someone can help me with this.如您所见,我在这里很迷茫,但我希望有人可以帮助我。 If you need more information, just ask for them, I would be happy to provide them.如果您需要更多信息,请向他们索取,我很乐意提供。

Please bear with me, since I need clear instructions, so I get everything right ^^ also, please excuse my English, since I'm not a native speaker请多多包涵,因为我需要明确的指示,所以我什么都做对了^^另外,请原谅我的英语,因为我不是母语人士

Thanks in advance for your answers :)提前感谢您的回答:)

I still don't know how this worked at the second, or it generally works, but this solved my problem: Laravel backpack restrict user access to admin panel .我仍然不知道第二个是如何工作的,或者它通常可以工作,但这解决了我的问题: Laravel 背包限制用户访问管理面板

But feel free if you want to add something to this solution or my question^^但是,如果您想对此解决方案或我的问题添加一些内容,请随意^^

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

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