How To Request Path And Method In Laravel Framework

admin_img Posted By Bajarangi soft , Posted On 17-09-2020

The input values can be easily retrieved in Laravel. No matter what method was used “get” or “post”, the Laravel method will retrieve input values for both the methods the same way. There are two ways we can retrieve the input values. Using the input() method. Using the properties of Request instance.

How To Request Path And Method In Laravel Framework


The Illuminate\Http\Request instance provides a variety of methods for examining the HTTP request for your application and extends the Symfony\Component\HttpFoundation\Request class. We will discuss a few of the most important methods below.

Retrieving The Request Path

The path method returns the request's path information. So, if the incoming request is targeted at http://domain.com/foo/bar, the path method will return foo/bar:
 

$uri = $request->path();
 

The is method allows you to verify that the incoming request path matches a given pattern. You may use the * character as a wildcard when utilizing this method:

if ($request->is('admin/*')) {
//
}


Retrieving The Request URL

To retrieve the full URL for the incoming request you may use the url or fullUrl methods. The url method will return the URL without the query string, while the fullUrl method includes the query string:

// Without Query String...
$url = $request->url();

// With Query String...
$url = $request->fullUrl();


Retrieving The Request Method

The method method will return the HTTP verb for the request. You may use the isMethod method to verify that the HTTP verb matches a given string:

$method = $request->method();

if ($request->isMethod('post')) {
//
}




For Example(1)
 when you request data from a form.blade.php file you just $request->path() method in demoController so that you get from which route ur getting data

To know more about Accessing the request visit our Bajarangisoft site.


Implement code as below in demoController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class demoController extends Controller
{
    public function form(){

       return view('form');
    }
    public function formstore(Request $request){

        return $request->path();
    }
  
}

 

Related Post