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

Laravel Requests

Laravel Requests — Structure map

Clickable & Draggable!

Laravel Requests — Related pages: