To get the details of the HTTP request you need to make use of the class IlluminateHttpRequest.
使用上面的类,您将能够从HTTP请求中获取输入、cookies和文件。现在考虑以下表单 -
To get all the details from the HTTP request you can do as follows −
Example 1
的翻译为:示例 1
Using $request->all() method
在下面的表单中输入以下详细信息:
Once you submit it will retrieve all the input data and return an array with data.
'public function validateform(Request $request) {
$input = $request->all();
print_r($input);
}
输出
The output of the above code is −
'Array (
[_token] => 367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx
[name] => Rasika Desai
[email] => rasika@gmail.com
[age] => 20
[address] => Pune
)
Example 2
的中文翻译为:示例2
Using $request->collect() method.
This method will return the data as a collection.
'public function validateform(Request $request) {
$input = $request->collect();
print_r($input);
}
输出
The output of the above code is −
'IlluminateSupportCollection Object (
[items:protected] => Array(
[_token] => 367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx
[name] => Rasika Desai
[email] => rasika@gmail.com
[age] => 20
[address] => Pune
)
[escapeWhenCastingToString:protected] =>
)
Example 3
使用 $request->getContent() 方法。
此方法将输出为URL查询字符串,数据以键/值对的形式传递。
'public function validateform(Request $request) {
$input = $request->getContent();
echo $input;
}
输出
The output of the above code is
'_token=367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx&name=Rasika+Desai&email=rasika%40gmail.com&age=20&address=Pune
Example 4
使用 php://input
这将返回来自URL查询字符串中输入字段的数据。
'$data = file_get_contents('php://input');
print_r($data);
输出
The output of the above code is −
'_token=367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx&name=Rasika+Desai&email=rasika%40gmail.com&age=20&address=Pune