微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 lravel 中使用自定义表单请求时请求助手为空?

如何解决在 lravel 中使用自定义表单请求时请求助手为空?

我创建了名为 CreatedAtFilterRequest 的自定义表单请求。我添加到这个请求是这样的:

 public function show(CreatedAtFilterRequest $request,$id)
{
    $wallet = Http::get($this->endpoint . "/test/{$id}")->json();

    $request->merge([
        'id' => $request['id'] ?? $id,'inline' => true,]);

    dd(request()->all()); // this is null
    dd($reques->all()); // this is ok
}

为什么 dd(request()->all() 为空?

我需要像这样在刀片中请求外观:

<input type="text" name="id" class="form-control" value="{{ request('id') }}">

但是 'request('id')' 为空。

解决方法

看起来合并请求数据是空的。所以你可以做以下事情

 request()->merge([
        'id' => $request['id'] ?? $id,'inline' => true,]);

如果它有 Request 而不是 CreatedAtFilterRequest 那么它就可以了。看起来它对待 CreatedAtFilterRequest 实例与 Request 实例不同

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。