HTTP Requests

Accessing the Request Instance

To access the current Request object you can inject it into your Controller by using the Rareloop\Lumberjack\Http\ServerRequest type hint, e.g.
1
use Rareloop\Lumberjack\Http\ServerRequest;
2
3
class MyController
4
{
5
public function show(ServerRequest $request)
6
{
7
8
}
9
}
Copied!
You can also use the request() helper to access the request from anywhere in your theme:
1
use Rareloop\Lumberjack\Helpers;
2
3
$request = Helpers::request();
4
5
// Or if you have global helpers enabled:
6
$request = request();
Copied!

Usage

Get the method

1
$request->getMethod(); // e.g. GET
2
$request->isMethod('GET'); // e.g. true
Copied!

Get the path

1
$request->path(); // e.g. /path
Copied!

Get the URL

1
$request->url(); // e.g. http://test.com/path
2
$request->fullUrl(); // e.g. http://test.com/path?foo=bar
Copied!

Get all query params

1
$request->query();
Copied!

Get a specific query param

1
$request->query('name');
2
$request->query('name', 'Jane'); // Defaults to "Jane" if not set
Copied!

Get all post params

1
$request->post();
Copied!

Get a specific post param

1
$request->post('name');
2
$request->post('name', 'Jane'); // Defaults to "Jane" if not set
Copied!

Get all input params

1
$request->input();
Copied!

Get a specific input param

1
$request->input('name');
2
$request->input('name', 'Jane'); // Defaults to "Jane" if not set
Copied!

Does the request have a specific input key?

1
if ($request->has('name')) {
2
// do something
3
}
4
5
if ($request->has(['name', 'age'])) {
6
// do something if both 'name' and 'age' are present
7
}
Copied!