Skip to content

there is a difference between $request and request() #42765

@Ham3D

Description

@Ham3D
  • Laravel Version: 9.x
  • PHP Version: 8.1
  • Database Driver & Version:

Description:

when you attach something to $request , you dont have access to it when you call request()->get('something');

Steps To Reproduce:

There is a wired bug in the request.
I fetch something inside a policy class (which is loaded inside a FormRequest class)
imagine i have to:

$chat = Chat:first();

and then inside my services i need to again get this $chat, but because i have it in the first place, i do this inside policy [here we dont have access to $request, so i used request() helper]:

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

or

request()->merge(['chat' => $chat]);

the final result is the same (both buggy)

and inside my services, or in controller, etc, i do this:

$chat = $request->get('chat');    // this will be null
$chat = request()->get('chat') // this one has the actual chat model

Test case :

https://github.com/Ham3D/bug-report

there is a test, controller, policy, and request.
also I attached an SQLite db just in case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions