user1638279
user1638279

Reputation: 523

Routing and controllers

I am new to laravel and just tried some examples. This is:

laravel-master\app\controllers\account.php -

class AccountController extends BaseController
{
    public function action_index()
    {
        echo "This is the profile page.";
    }
    public function action_login()
    {
        echo "This is the login form.";
    }
    public function action_logout()
    {
        echo "This is the logout action.";
    }
}

Then i added one line at - laravel-master\app\routes.php

Route::controller('account');

So when i will go to the main page

but its showing

Don't know what is the problem . Am i wrong somewhere ?

Upvotes: 1

Views: 2901

Answers (2)

Makita
Makita

Reputation: 1812

Change the name of the controller file to:

laravel-master\app\controllers\AccountController.php

Change the route definition to:

Route::controller('account', 'AccountController');

Change the controller methods to:

class AccountController extends BaseController
{
    public function getIndex()
    {
        echo "This is the profile page.";
    }
    public function getLogin()
    {
        echo "This is the login form.";
    }
    public function getLogout()
    {
        echo "This is the logout action.";
    }
}

Upvotes: 7

severin
severin

Reputation: 2126

Not a Laravel expert, but I think your Route::controller is missing an argument for the destination of the route and you should use the full name of the controller class. Try

Route::controller('account', 'AccountController')

I am also not sure about the action_s. If I understand the documentation on controllers correctly, they have to be prefixed with an HTTP verb, e.g.

public function getIndex()

instead of

public function action_index()

Upvotes: 1

Related Questions