gpt4 book ai didi

php - Controller 没有来自中间件的更改请求

转载 作者:行者123 更新时间:2023-12-04 10:37:09 24 4
gpt4 key购买 nike

我有一个自定义中间件,可以编辑这样的请求:

public function handle($request, Closure $next)
{
$profileLocal = ProfileLocal::where(
'id', JWTHelper::tokenExtractProfileLocalID($request->token)
)->with('status')->first();

if (empty($profileLocal) || $profileLocal->status->email_verified == 0 || $profileLocal->status->blocked == 1) {
return $this->respondError('You dont have access to this store', 336);
}

$request->profileLocal = $profileLocal;

return $next($request);
}

但是,当我尝试访问 $request->profileLocal 时在我的 Controller 中:
public function deviceSet(DeviceRequest $request)
{
dd($request->profileLocal);
}

如果我尝试 dd(request()->profileLocal),即使在我的 DeviceRequest 中,我也会返回 null它工作正常吗?
有谁知道我在这里可能做错了什么?
我注意到如果我使用 request()->profileLocal在我的 Controller 中它按预期工作

最佳答案

如果您想向请求添加一个值并能够将其作为属性访问,您可以将其添加到基础 request属性(property):

$request->request->add([
'profileLocal' => $profileLocal
]);

// or $request->request->add(compact('profileLocal'))

然后,您将能够通过以下方式访问 Controller 中的值:
$request->profileLocal

当您调用 all() 之类的方法时,也会包含此值。或 input() .

关于php - Controller 没有来自中间件的更改请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60116779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com