0

I just started with PHP Laravel and i couldn't figure out how to create a default route.

With ASP.NET MVC you could create a default route that would point to the requested controller and action. So you don't have to create a new route for each controller & action.

Is this possible?

Something like:

Route::get('{controller}/{index}', 'HomeController@index');

The HomeController would be the default is no controller was specified and index would be the default action if no action was specified.

Jamie
  • 3,031
  • 5
  • 36
  • 59

2 Answers2

0

You can create resource controllers in Laravel but the exact "default" functionality you are looking for doesn't exist out of the box. Check out the resource controllers:

http://laravel.com/docs/4.2/controllers#restful-resource-controllers

However, this is only really for RESTful routes.

If you want to create it manually then you want to do something like this:

Route::get('{controller}/{action}', function($controller, $action) {
    $controller = ucwords($controller).'Controller';
    App::make($controller)->{$action}();
});
Rupert
  • 1,629
  • 11
  • 23
0

You can use Route::controller

Take a look at this answer, it may be close to what you want

https://stackoverflow.com/a/18180606/4433967

Community
  • 1
  • 1