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();
}
}