0

Currently we're doing unit testing in Laravel, and I just noticed my colleague this line below (its working fine though). I look for a documentation in Laravel about this but I can't find it. It seems all we're just focusing on getting the request input values in the documentation.

use Illuminate\Http\Request;
// ...more code here
$request = Request::create('/users/all', 'GET');

I just wanna ask how to pass a parameter using the above code line? And someone can give me a documentation about that.

schutte
  • 1,949
  • 7
  • 25
  • 45
  • Just check the create method signature: function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null) – Mohsen Feb 21 '21 at 11:37

2 Answers2

2

Check the create function at here: https://github.com/symfony/symfony/blob/5cfe73d95419bac1ffdddc4603db7266e428b454/src/Symfony/Component/HttpFoundation/Request.php#L336

As you can see, you can pass parameteres as third argument: Example:

Request::create('/users/all', 'GET', ['username' => 'admin']);

Note: Laravel Request extends Symfony Base Request class

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Mohsen
  • 309
  • 3
  • 15
2

The 3rd argument to create is for an array of parameters. Illuminate\Http\Request extends Symfony\Component\HttpFoundation\Request which defines the create method:

public static function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null)
lagbox
  • 48,571
  • 8
  • 72
  • 83