0
votes

i'm pretty new to laravel and i have problem with routing

in my routes.php

Route::controller('users', 'userController');

i have a file called userController.php in my controllers directory

userController :

<?php

class userController extends BaseController {
public $restful = true ;


    public function index()
    {
        echo 'hello';
    }
    public function check()
    {
        echo 'check';
    }
}

when i run http://localhost/larave/public/users

i get NotFoundHttpException

Symfony\Component\HttpKernel\Exception\NotFoundHttpException
…\bootstrap\compiled.php4921
Illuminate\Routing\Router handleRoutingException
…\bootstrap\compiled.php4766
Illuminate\Routing\Router findRoute
…\bootstrap\compiled.php4754
Illuminate\Routing\Router dispatch
…\bootstrap\compiled.php481
Illuminate\Foundation\Application dispatch
…\bootstrap\compiled.php470
Illuminate\Foundation\Application run
…\public\index.php49

what's wrong ? it works fine when i do routing for each controller/action like

Route::get('users/check', 'userController@check');

1
You labeled this as laravel and laravel 4.. what version are you using? - Rob W

1 Answers

0
votes

RESTful controller methods need to be prefixed with the HTTP VERB.. such as get and post.

Example:

class userController extends BaseController {
  public function getIndex() {
    return "I am echoing only when you GET me!";
  }

  public function postIndex() {
    return "I am echoing only when you POST to me!";
  }
}