I have the following routes set up in my Laravel 4 application:

Route::get('/news', 'NewsController@index');
Route::get('/news/{slug}', 'NewsController@view');

In my NewsController.php file, I have the appropriate actions set up that return views. Now, when I browse to /news, I get an error message like so:

Some mandatory parameters are missing ("slug") to generate a URL for route "get /news/{slug}

and when I browse to /news/test-post it all works fine.

What's weird is that if I comment out the route for /news/{slug} and browse to /news, this error gets thrown:

Unknown action [NewsController@view].

even though the route for /news doesn't touch the view action, it uses index.

有帮助吗?

解决方案

Are you sure you haven't defined a RESTful controller routing before? Like:

Route::controller('/news', 'NewsController');

If you have, put the Route::get before the Route::controller. Otherwise I don't really know whats wrong, I couldn't reproduce the error with your setup.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top