假设我有以下路线:
Route::post('api/{call}', array('as' => 'apiCaller', 'uses' => 'ApiController@apiCaller'));
我希望此路由能够调用call
参数中指定的变量API。在call
参数之后,我希望请求者能够以key=value
的典型格式提交具有可变数量参数的帖子,具体取决于所请求的API。
我该怎么做呢?我应该检查随请求发送的$ _POST数组,还是Laravel有特殊要求?
答案 0 :(得分:0)
只需使用Input类,就像@Sam告诉你的那样:
class ApiController
{
public function apiCaller($call)
{
$inputs = Input::all();
// now $inputs is an array with all the key=> value pair sent, or an empty
// array if none has been passed
}
}
这一点以及更多内容都写在http://laravel.com/docs/requests#basic-input
答案 1 :(得分:0)
您可以使用Input
课程来获取$_POST
或$_GET
的所有用户数据,例如:
Input::get('keyname'); // get only one item by keyname
Input::all(); // returns all user submitted data from all input sources
Input::only(array('key1', 'key2')); // Only these two mentioned
Input::except('_token'); // get all but _token
如果您希望用户使用网址提交数据(无限制参数),则必须使用query string
,例如:
http://example.com?key1=value1&key2=valye2 // So on...
为此,您无需修改route
,只需在url
中添加参数即可。要提交到$_POST
,它不需要使用url
传递参数,但是您使用的方法(POST / GET),以检索用户提交的数据,您可以使用相同的Input
{{1}} 1}}方法。