Laravel Request

Laravel - Request :

In this part, you will learn in insight regarding Requests in Laravel.

Retrieving the Request URI

The path technique is utilized to recover the asked for URI. The is technique is utilized to recover the asked for URI which coordinates the specific example determined in the contention of the strategy. To get the full URL, we can utilize the url method.


Step 1 − Execute the underneath direction to make another controller called UriController.

php craftsman make:controller UriController – plain 

Step 2 − After effective execution of the URL, you will get the accompanying yield −


Step 3 − After making a controller, include the accompanying code in that file.



namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Http\Controllers\Controller; 

class UriController extends Controller { 

public function index(Request $request){ 

//Usage of way method 

$path = $request->path(); 

reverberation 'Path Method: '.$path; 

reverberation '<br>'; 

//Usage of is method 

$pattern = $request->is('foo/*'); 

reverberation 'is Method: '.$pattern; 

reverberation '<br>'; 

//Usage of url method 

$url = $request->url(); 

reverberation 'URL technique: '.$url; 



Step 4 − Add the accompanying line in the app/Http/route.php file.



Step 5 − Visit the accompanying URL.


Step 6 − The yield will show up as appeared in the accompanying image.

Path Method

Retrieving Input

The input esteems can be effectively recovered in Laravel. Regardless of what strategy was utilized get or post, the Laravel technique will recover input qualities for both the strategies a similar way. There are two different ways we can recover the info values.

  • Using the information() method
  • Using the properties of Request instance

Using the information() method

The input() strategy takes one contention, the name of the field in structure. For instance, in the event that the structure contains username field, at that point we can get to it by the accompanying way.

$name = $request->input('username'); 

Using the properties of Request instance

Like the input() strategy, we can get the username property specifically from the demand instance.



Observe the accompanying guide to see progressively about Requests −

Step 1 − Create a Registration structure, where client can enlist himself and store the structure at resources/sees/register.php



<title>Form Example</title> 



<form action = "/client/register" method = "post"> 

<input type = "concealed" name = "_token" esteem = "<?php reverberation csrf_token() ?>"> 




<td><input type = "text" name = "name" /></td> 




<td><input type = "text" name = "username" /></td> 




<td><input type = "text" name = "password" /></td> 



<td colspan = "2" align = "center"> 

<input type = "submit" value