How to set the default controller in Laravel?

DisgruntledGoat picture DisgruntledGoat · Jan 18, 2013 · Viewed 29k times · Source

I'm using the Laravel PHP framework and am wondering about a few things. The default application/routes.php file contains this:

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

This just outputs the view, but how do I call a controller from there?

I can delete the entire route above and replace it with Route::controller('home') which seems to use the home controller on the default URL (i.e. example.com/). But any other controller like Route::controller('article') doesn't work, only on example.com/article. How would I set the article controller as the default?

Answer

Joseph Silber picture Joseph Silber · Jan 18, 2013

Just pass the controller as a string, with @ between the class name and the method name:

Route::get('/', 'article@index');

Read the docs (scroll to the example by the title Registering a route that points to a controller action).