JasonMortonNZ JasonMortonNZ - 11 months ago 39
PHP Question

Laravel routes not working?

I've just started learning the Laravel framework and am having an issue with the routing.

The only route that is working is the default home route that's attached to Laravel out of the box.

I'm using WAMP on Windows and it uses PHP 5.4.3, and Apache 2.2.22, and I also have mod_rewrite enabled, and have removed the 'index.php' from the application.php config file to leave an empty string.

I've created a new controller called User:

class User_Controller extends Base_Controller {

public $restful = true;

public function get_index()
return View::make('user.index');

I've created a view file in application/views/user/ called index.php with some basic html code, and in routes.php I've added the following:

Route::get('/', function()
return View::make('home.index');

Route::get('user', function()
return View::make('user.index');

The first route to works fine when visiting the root (
) in my web browser, but when I try to go to my second route with
I get a 404 Not Found error. Why would this be happening?

Answer Source

Have you tried adding this to your routes file instead Route::get('user', "user@index")?

The piece of text before the @, user in this case, will direct the page to the user controller and the piece of text after the @, index, will direct the script to the user function public function get_index().

I see you're using $restful, in which case you could set your Route to Route::any('user', 'user@index'). This will handle both POST and GET, instead of writing them both out separately.