1
votes

I'm trying to define named routes together with a RESTful controller. In my routes.php I have this:

Route::controller('blog', 'BlogController', array('getIndex' => 'home'));
Route::controller('login', 'LoginController');

And the method in BlogController:

public function getIndex()
{      
    return View::make('blog.home');
}

When I try to access /home I receive a NotFoundHttpException, all other routes work as expected.

Shouldn't this work? I found this third parameter for Route::controller() at this post.

1
Mr. Bruni, if you can please convert your comments to an answer.user2094178
Ok... I have converted my comments to an answer (and deleted the comments).J. Bruni

1 Answers

2
votes

The "route name" is internal.

Quoting the mentioned post: "you can pass an array of method names and their corresponding route name as the third parameter to Route::controller"...

So, your array attaches getIndex method to the home route name. But "route name" is one thing, internal to the app, but not an externally accessible URL, as you try to use it.

You may attach the URL to the named route with something like this:

Route::get('home', array('as' => 'home'));

In this case, the first "home" is the URL part, while the second "home" is the route name (which you attached to "getIndex" method). See http://laravel.com/docs/routing#named-routes

With a named route we can use an identifier for a route (for example, the name "dashboard") but later, at any moment, we can make it accessible through any URL, without the need to make a global search and replace throughout the whole application code. We can attach the "main" or "home" URL path to the "dashboard" named route... so... "the route name is internal".