To access the current Request object you can inject it into your Controller by using the Rareloop\Lumberjack\Http\ServerRequest
type hint, e.g.
use Rareloop\Lumberjack\Http\ServerRequest;
class MyController
{
public function show(ServerRequest $request)
{
}
}
You can also use the request()
helper to access the request from anywhere in your theme:
use Rareloop\Lumberjack\Helpers;
$request = Helpers::request();
// Or if you have global helpers enabled:
$request = request();
$request->getMethod(); // e.g. GET
$request->isMethod('GET'); // e.g. true
$request->path(); // e.g. /path
$request->url(); // e.g. http://test.com/path
$request->fullUrl(); // e.g. http://test.com/path?foo=bar
$request->query();
$request->query('name');
$request->query('name', 'Jane'); // Defaults to "Jane" if not set
$request->post();
$request->post('name');
$request->post('name', 'Jane'); // Defaults to "Jane" if not set
$request->input();
$request->input('name');
$request->input('name', 'Jane'); // Defaults to "Jane" if not set
if ($request->has('name')) {
// do something
}
if ($request->has(['name', 'age'])) {
// do something if both 'name' and 'age' are present
}