Lumberjack
WebsiteRareloopTimber DocumentationTwig Documentation
v6
v6
  • Introduction
  • What's New
  • Upgrade Guide
  • Getting Started
    • Installation
    • Configuration
  • The Basics
    • Lifecycle
    • Routing
    • WordPress Controllers
    • Post Types
    • Query Builder
    • View Models
    • HTTP Requests
    • HTTP Responses
    • Middleware
    • Sessions
    • Helpers
    • Collections
  • Container
    • Using the Container
    • Service Providers
    • Facades
  • Misc
    • Contributing
    • Notable Mentions
    • Code of Conduct
    • View on GitHub
    • View Docs on GitHub
    • Submit an issue
Powered by GitBook
On this page
  • Accessing the Request Instance
  • Usage
  • Get the method
  • Get the path
  • Get the URL
  • Get all query params
  • Get a specific query param
  • Get all post params
  • Get a specific post param
  • Get all input params
  • Get a specific input param
  • Does the request have a specific input key?
  1. The Basics

HTTP Requests

PreviousView ModelsNextHTTP Responses

Last updated 2 years ago

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.

use Rareloop\Lumberjack\Http\ServerRequest;

class MyController
{
    public function show(ServerRequest $request)
    {

    }
}

You can also use the request() 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();

Usage

Get the method

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

Get the path

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

Get the URL

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

Get all query params

$request->query();

Get a specific query param

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

Get all post params

$request->post();

Get a specific post param

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

Get all input params

$request->input();

Get a specific input param

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

Does the request have a specific input key?

if ($request->has('name')) {
    // do something
}

if ($request->has(['name', 'age'])) {
    // do something if both 'name' and 'age' are present
}
helper