phplaravelread-eval-print-looptinker

How to fill Request object in command line REPL tool Tinker with emulated data of real http request


Using Laravel framework and it's REPL named Tinker in my project, I want to set the request object to the same state it would be if I made some real HTTP request through my browser.

When I dump the request using

 dd($request);

I receive a lot of data in $request like headers, form input data, and so on.

I want to receive the same data in $request in Tinker REPL.

How can I emulate HTTP request in Tinker from the command line?


Solution

  • Request class has some set of methods to initiate it with names begins from create... And the create method allow to initiate it with manually gived params like url, method and additional optional parameters:

    Illuminate\Foundation\Http\FormRequest::create('http://your-url', 'METHOD', ...)

    so you can use it from REPL to play with your controllers and initiate them like you come from some route