Khean
Khean

Reputation: 99

How to add a new function to crud controller in Laravel 4?

I'm using Resourceful controller which there are default functions such as index, create, store, show, edit, update and destroy. My question is that how can I add my own function to that controller? For instance I add a function in that controller like this:

class Account extends \Eloquent {
.
.
.
        /**
         * Attempt login.
         * GET /accounts/login
         *
         * @return Response
         */
        public function login()
        {
            //
            echo "You are in login page";
        }

But it seems not work when i enter that url: account/login. This is my route file:

Route::resource('account', 'AccountsController');

Upvotes: 0

Views: 1306

Answers (1)

Unnawut
Unnawut

Reputation: 7578

You need to add a separate route for it, and the route needs to come before Laravel generates the routes for the resource controller.

Route::get('account/login', 'AccountsController@login');
Route::resource('account', 'AccountsController');

Upvotes: 2

Related Questions