简体   繁体   English

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

[英]request helper is null when use custom form request in lravel?

I Create Custom form request called CreatedAtFilterRequest.我创建名为 CreatedAtFilterRequest 的自定义表单请求。 i add to this request like this:我添加到这个请求是这样的:

 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
}

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

i need request facade in blade like this:我需要像这样在刀片中请求外观:

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

but 'request('id')' is null.但 'request('id')' 为空。

Look like merge request data is null .So you can do the following看起来合并请求数据为 null 。因此您可以执行以下操作

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

If it had Request instead of CreatedAtFilterRequest then it woks.Looks like it treat CreatedAtFilterRequest instance is different then Request instance如果它有Request而不是CreatedAtFilterRequest那么它会工作。看起来它对待CreatedAtFilterRequest实例与Request实例不同

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

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