dqy92287 2014-06-20 20:46
浏览 49
已采纳

如何在Laravel 4中为crud控制器添加新功能?

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');
  • 写回答

1条回答 默认 最新

  • dongshan1396 2014-06-20 21:14
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部