如果要获取当前的请求信息,可以使用Illuminate\Http\Request类,当前请求实例会被服务容器自动注入:
~~~
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class IndexController extends Controller
{
/**
* 存储新用户
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$name=$request->input('name');
}
}
~~~
获取客户端信息
~~~
// 返回请求实例
// echo $request->instance();
// 返回请求类型
// echo $request->method();
// 获取应用程序的根URL
// echo $request->root();
// 获取请求的URL(无查询字符串)。
// echo $request->url();
// 获取ip地址
echo $request->ip();
~~~
输出结果
~~~
GET /index.php/index HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding: gzip, deflate, sdch, br Accept-Language: zh-CN,zh;q=0.8 Connection: close Host: 127.0.0.1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
GET
http://127.0.0.1/index.php
http://127.0.0.1/index.php/index
127.0.0.1
~~~
具体方法参考源码