我正在使用此软件包进行维护,但要定义哪些用户可以在停机期间访问该站点以及哪些用户不能有问题。
在过去的几天里,我一直在搜索并且阅读了很多内容,因为主控制器在中间件之后加载,它无法检测用户状态是否登录。(我不知道我只是反复看到)
无论如何,这是问题所在:
我希望允许Admin
具有访问该站点角色的用户在停机时间,并且visitors
,other group of users
不要。
到目前为止我做了什么
根据包文档,我App\Exemptions\AdminExemption.php
用这些数据制作了客户文件:
<?php
namespace App\Exemptions;
use Auth; use Config; use App\User; use MisterPhilip\MaintenanceMode\Exemptions\MaintenanceModeExemption;
class AdminExemption extends MaintenanceModeExemption {
public function isExempt()
{
if (Auth::check() && Auth::user()->role == 'Admin') {
return true;
}
else {
return false;
}
//if user is logged and it's admin show the site
//if user is logged and isn't admin hide the site
//if user isn't logged (is visitor) hide the site
} }
我在包配置文件中注册了这个文件config\maintenancemode.php
'exemptions' => [
App\Exemptions\AdminExemption::class,
],
并用 laravel 默认替换包类Kernel
protected $middleware = [
// \App\Http\Middleware\CheckForMaintenanceMode::class,
\MisterPhilip\MaintenanceMode\Http\Middleware\CheckForMaintenanceMode::class,
//others...
]
问题
Auth::check()
或者auth()->user()
这些Auth::user()
都不能检测到登录的用户并假设用户没有登录(是访客)。因此,该网站对所有人甚至管理员都关闭。
问题
如何在AdminExemption.php
文件中获取当前用户的真实状态?
地位
- 是用户(是管理员)
show the site
- 是用户(不是管理员)
don't show the site
- 不是用户(访客)
don't show the site
任何的想法?