Laravel Request Cheat Sheet: Essential Methods Every Backend Developer Should Know
This concise Laravel Request cheat sheet enumerates the most useful Request facade methods—covering URL retrieval, path handling, headers, IP detection, AJAX checks, and content format detection—to help backend developers quickly access HTTP request data in their applications.
Laravel Request Cheat Sheet
In Laravel, the Request facade provides a convenient way to access HTTP request data. The following list presents the most frequently used methods for retrieving URLs, paths, headers, client information, and request characteristics.
// Retrieve all input data (form-data or raw)
request()->input();
// Full URL
Request::url();
// Path component of the URL
Request::path();
// Full request URI (including query string)
Request::getRequestUri();
// Client IP address
Request::ip();
// Full URI with scheme
Request::getUri();
// Query string only
Request::getQueryString();
// Request port (e.g., 80, 443)
Request::getPort();
// Check if current URI matches a pattern
Request::is('foo/*');
// Get a specific segment of the URI (1‑based index)
Request::segment(1);
// Retrieve a header value
Request::header('Content-Type');
// Retrieve a server variable
Request::server('PATH_INFO');
// Determine if the request is an AJAX call
Request::ajax();
// Determine if the request uses HTTPS
Request::secure();
// Get the HTTP method (GET, POST, etc.)
Request::method();
// Check if the method matches a given type
Request::isMethod('post');
// Get raw POST content
Request::instance()->getContent();
// Get the expected response format
Request::format();
// Determine if the request expects JSON
Request::isJson();
// Determine if the client accepts JSON
Request::wantsJson();This cheat sheet serves as a quick reference for developers working with Laravel's request handling features.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
