简体   繁体   中英

request helper is null when use custom form request in lravel?

I Create Custom form request called 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?

i need request facade in blade like this:

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

but 'request('id')' is null.

Look like merge request data is null .So you can do the following

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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