Laravel Requests
Laravel Requests
When using dynamic properties, Laravel will first look for the parameter's value in the request payload.
Allows you to keep input from one request during the next request.
Accessing The Request
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Store a new user.
*
* @param Request $request
* @return Response
*/ public function store(Request $request)
{
$name = $request->input('name');
//
}
}
To obtain an instance of the current HTTP request via dependency injection, you should type-hint the Illuminate\Http\Request class on your controller method.
Input Trimming & Normalization
Laravel includes the TrimStrings and ConvertEmptyStringsToNull middleware in your application's global middleware stack.
Retrieving Input
Configuring Trusted Proxies
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
*/
protected $proxies = [
'192.168.1.1',
'192.168.1.2',
];
/**
* The headers that should be used to detect proxies.
*
* @var string
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
In addition to configuring the trusted proxies, you may configure the proxy $headers that should be trusted.
Related concepts
- Route Model Binding: Implicit Binding
- Laravel Routing: Fallback Routes
- Laravel Routing: Form Method Spoofing
- Laravel Middleware
- Defining Middleware: Before & After Middleware
- Registering Middleware: Global Middleware
- CSRF Protection: CSRF token
- Laravel Controllers
- Dependency Injection & Controllers: Method Injection
- Laravel Requests: Accessing The Request
- Accessing The Request: Accessing The Request Via Route Closures
- Accessing The Request: Request Path & Method
- Request Path & Method: Retrieving The Request Path
- Request Path & Method: Retrieving The Request URL
- Request Path & Method: Retrieving The Request Method
- Accessing The Request: PSR-7 Requests
- Retrieving Input: Retrieving An Input Value
- Retrieving Input: Retrieving Input Via Dynamic Properties
- Retrieving Input: Determining If An Input Value Is Present
- Old Input: Flashing Input To The Session
- Old Input: Retrieving Old Input
- Cookies: Retrieving Cookies From Requests
- Files: Retrieving Uploaded Files
- Basic Routing: Laravel CSRF Protection
- Rate Limiting: Dynamic Rate Limiting
- Signed URLs: Validating Signed Route Requests
- Laravel URL Generation: Default Values
- A Note On Optional Fields: AJAX Requests & Validation
- Laravel Validation: Form Request Validation
- Form Request Validation: Creating Form Requests
- Form Request Validation: Adding After Hooks To Form Requests
- Form Request Validation: Authorizing Form Requests
- Laravel Validation: Manually Creating Validators
- Laravel Request Lifecycle
- Laravel Request Lifecycle: HTTP / Console Kernels
- HTTP / Console Kernels: Dispatch Request
- Laravel Service Providers: Deferred Providers
- Read & Write Connections: The sticky Option
- Adding Custom Guards: Closure Request Guards
- Issuing Access Tokens: Managing Clients
- Requesting Tokens: Approving The Request
- Laravel API Authentication: Token Scopes
- CSRF
- Laravel Requests: Input Trimming & Normalization
- Laravel Requests: Retrieving Input
- Laravel Requests: Configuring Trusted Proxies