Laravel Request - Laravel

What is the use of Laravel Request ?

Retrieving the Request URI

To retrieve the requested URI, “path” method will be used. The “is” method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method. User can use the “url” method to get full URL.

Example

Step 1 − Execute the below command to create a new controller calledUriController.

Step 2 – User can see the following output, after successful execution of the URL

uricontroller

Step 3 – Create a controller and add the following code in that file.

app/Http/Controllers/UriController.php

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

app/Http/route.php

Step 5 − Visit the following URL.

http://localhost:8000/foo/bar

Step 6 − Output will be displayed as in the below image.

path_method

Retrieving Input

Laravel retrieving input method will retrieve input values for both methods same way, either “get” and “post”. There are two ways we can retrieve the input values.

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

Using the input() method

The input() method has only argument, it is the name of the field in form. For example, if the form contains username field then, user can access it by using below

Using the properties of Request instance

User can get the username property directly from the request instance like the input() method

Step 2 − Execute the below command to create a UserRegistrationcontroller.

Step 3 − User can see the below output, after successful execution.

userregistration

Step 4 − Copy the following code in app/Http/Controllers/UserRegistration.php controller.

app/Http/Controllers/UserRegistration.php

Step 5 − Add the following line in app/Http/routes.php file.

app/Http/routes.php

Step 6 – User can see the registration form as displayed in the following picture by visiting the following URL. Type the registration details and click Register to see on the second page, for the displayed the user registration details.

http://localhost:8000/register

Step 7 − Output can be seen as shown in the below images.

registration

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Laravel Topics