schutte
schutte

Reputation: 2166

How to pass parameter using laravel's Request?

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.

Upvotes: 0

Views: 2102

Answers (2)

Mohsen
Mohsen

Reputation: 307

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

Upvotes: 2

lagbox
lagbox

Reputation: 50541

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)

Upvotes: 2

Related Questions