Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Named restful routes in Laravel 4

So, I've been able to get restful controllers working with

Route::controller('users','UserController');

class UserController extends BaseController {
    public function getAccount(){}
}

and so /users/account works. However if I try to do something like

Route::any('account',array('as' => 'account','uses' => 'UserController@account'));

and go to /account, it doesn't work (NotFoundHTTPException). Is there a way to use named routes and restful controllers in conjunction? I like how the restful system breaks up requests, and how named routes encapsulate the URI's and decouple them from the function names. This worked in Laravel 3. Am I missing something in the syntax, or did Laravel 4 purposefully disallow this kind of mix-and-match behavior? Thanks...

like image 364
Osan Avatar asked Nov 29 '22 12:11

Osan


1 Answers

This would depend entirely on the order you have defined the routes. If it's not working try reversing the order of the definitions.

But because Laravel is all about making your life easier you can pass an array of method names and their corresponding route name as the third parameter to Route::controller.

Route::controller('users', 'UsersController', ['getProfile' => 'user.profile']);

This might not directly apply to your situation but it is super handy.

like image 78
Jason Lewis Avatar answered Jan 31 '23 07:01

Jason Lewis