Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default controller in Laravel?

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?

like image 694
DisgruntledGoat Avatar asked Jan 18 '13 16:01

DisgruntledGoat


1 Answers

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).

like image 123
Joseph Silber Avatar answered Sep 22 '22 02:09

Joseph Silber