我目前正尝试如下路线:
如果用户获取 /account/
如果会话有account_id
,则用户登录; 显示他的帐户信息
如果没有,用户没有登录; 显示登录/创建表单
如果用户POST /account/
如果输入create
,则用户想要创建帐户; 创造它
如果没有,用户想登录; 找到他的帐户然后再去/account/
我的路线是这样设定的:
Route::get('account', function() { if (Session::has('account_id')) return 'AccountsController@show'; else return 'AccountsController@index'; }); Route::post('account', function() { if (Input::has('create')) { return 'AccountsController@create'; else return 'AccountsController@login'; )};
这有点像我对Rails的处理,但我不知道如何指向控制器方法.我只是得到了返回的字符串.我没有在Laravel文档中找到它(我发现它很差,或者我搜索错了?)在任何其他网络教程中都没有.
请尝试以下方法:
Route::get('account', function() { if (Session::has('account_id')) { $action = 'show'; return App::make('AccountsController')->$action(); } else { $action = 'index'; return App::make('AccountsController')->$action(); } }); Route::post('account', function() { if (Input::has('create')) { $action = 'create'; return App::make('AccountsController')->$action(); } else { $action = 'login'; return App::make('AccountsController')->$action(); } )};