justmyfreak justmyfreak - 3 months ago 16
PHP Question

Getting GET "?" variable in laravel

Hello I'm creating API using REST and Laravel, I was following this article. Everything went well, but I want to map GET request to recognise variable using "?". For example:


My routes.php :

Route::any('api/v1/todos/(:num?)', array('as' => 'api.todos', 'uses' => 'api.todos@index'));

my 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);

How to recognise get parameter using "?" ?
Thank you and sorry for my bad English


Take a look at the $_GET and $_REQUEST superglobals. Something like the following would work for your example:

$start = $_GET['start'];
$limit = $_GET['limit'];


According to this post in the laravel forums, you need to use Input::get(), e.g.,

$start = Input::get('start');
$limit = Input::get('limit');

See also: http://laravel.com/docs/input#input