您好,我正在按照本文使用 REST 和 Laravel 创建API。
一切都按预期进行。
现在,我想映射一个 GET 请求以使用“?”识别变量。
例如:domain/api/v1/todos?start=1&limit=2
。
以下是我的内容routes.php
:
Route::any('api/v1/todos/(:num?)', array(
'as' => 'api.todos',
'uses' => 'api.todos@index'
));
我的controllers/api/todos.php
:
class Api_Todos_Controller extends Base_Controller {
public $restful = true;
public function get_index($id = null) {
if(is_null($id)) {
return Response::eloquent(Todo::all(1));
} else {
$todo = Todo::find($id);
if (is_null($todo)) {
return Response::json('Todo not found', 404);
} else {
return Response::eloquent($todo);
}
}
}
}
如何使用“?”获取参数 ?