Question

Folks,

I am trying to do something simple. If for example in my Settings navigation looks like this:

http://localhost/settings/   
http://localhost/settings/general
http://localhost/settings/message
http://localhost/settings/users

Is this possible in any way to make my router know that when it sees settings/users, I want it to go to SettingsController@users? and settings/general to go to SettingsController@general

Thing is, I dont want to have to put down each url in the routes.php like:

Route::any("settings/users", array("as" => "users", "uses" => "SettingsController@users"));
Route::any("settings/general", array("as" => "general", "uses" => "SettingsController@general"));

Is this possible in any way?

Was it helpful?

Solution

You need to use Route Controller in your routes.php like

Route::controller('settings', 'SettingsController');

and in your SettingsController define at the below methods.

class SettingsController extends BaseController {

    //URL : http://localhost/settings
    public function getIndex()
    {
        echo 'Index Method';

    }

    //URL : http://localhost/settings/message
    public function getMessage()
    {
        echo 'Message Method';
    }
}

You have to use 'get' prefix and start with Upper character. For more information please check http://laravel.com/docs/controllers#restful-controllers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top