php 在 Laravel 4 中的控制器内检索 GET 和 POST 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18761555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:11:03  来源:igfitidea点击:

Retrieving GET and POST data inside controller in Laravel 4

phplaravellaravel-4

提问by Jan

I've been searching the web for how to get POST data inside the controller, so far I have found two solutions: Input::get()and $_POST.

我一直在网上搜索如何在控制器中获取 POST 数据,到目前为止我找到了两个解决方案:Input::get()$_POST.

The comment for Input::get()reads:

评论Input::get()如下:

/**

 * Gets a "parameter" value.
 *
 * This method is mainly useful for libraries that want to provide some flexibility.
 *
 * Order of precedence: GET, PATH, POST
 *
 * Avoid using this method in controllers:
 *
 *  * slow
 *  * prefer to get from a "named" source
 *
 * It is better to explicitly get request parameters from the appropriate
 * public property instead (query, attributes, request).
 *
 * @param string  $key     the key
 * @param mixed   $default the default value
 * @param Boolean $deep    is parameter deep in multidimensional array
 *
 * @return mixed
 */

/**

 * Gets a "parameter" value.
 *
 * This method is mainly useful for libraries that want to provide some flexibility.
 *
 * Order of precedence: GET, PATH, POST
 *
 * Avoid using this method in controllers:
 *
 *  * slow
 *  * prefer to get from a "named" source
 *
 * It is better to explicitly get request parameters from the appropriate
 * public property instead (query, attributes, request).
 *
 * @param string  $key     the key
 * @param mixed   $default the default value
 * @param Boolean $deep    is parameter deep in multidimensional array
 *
 * @return mixed
 */

What is this "named" source they refer to? What is it I should use instead of Input::get()?

他们所指的这个“命名”来源是什么?我应该用什么来代替Input::get()

回答by bogartalamid

The documentationshows you can retrieve an input value for any HTTP verb by using Input::get().

文档显示您可以使用 检索任何 HTTP 动词的输入值 Input::get()

$name = Input::get('name');

回答by Ganesh Jogam

TO get all the inputs use Input::all()method. To check if specific column exists use Input::has('column_name')eg.Input::has('name'). To retrieve column value use Input::get('column_name')eg. Input::get('name').

获取所有输入使用Input::all()方法。要检查特定列是否存在,请使用Input::has('column_name')例如。Input::has('name'). 要检索列值使用Input::get('column_name')例如。Input::get('name').

回答by nageen nayak

You can get a parameter from url using :-

您可以使用以下方法从 url 获取参数:-

request()->urlParam;

if you want to get GET parameter using :-

如果您想使用以下方法获取 GET 参数:-

$request->get('current-password');

if you want to get POST parameter using :-

如果您想使用以下方法获取 POST 参数:-

$request->post('current-password');