路由和控制器

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\appoutes.php

Route::controller('account');

So when i will go to the main page

  • myproject/account/login it should show "This is the login form." .

but its showing

  • Missing argument 2 for Illuminate\Routing\Router::controller(), called in C:\Program Files\Zend\Apache2\htdocs\laravel-master\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 177 and defined.

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

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.";
    }
}

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()