如何在Laravel 5中创建用户登录/注册页面和业务登录/注册页面。我的AuthController使用:
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
我的routes.php正在使用:
Route::auth();
这适用于用户注册。如何为与用户不同的其他实体添加单独注册?
答案 0 :(得分:1)
您可以指定到不同控制器和/或操作的不同路由。
示例:
Route::auth();
$this->get('b_login', 'Auth\AuthController@showBusinessLoginForm');
$this->post('b_login', 'Auth\AuthController@businessLogin');
现在,您可以在Auth\AuthController
。
修改强>
我注意到使用第二个控制器进行业务注册/登录操作更简单。您可以在每个控制器中使用AuthenticatesAndRegistersUsers
特征。这意味着您只需要覆盖您想要适应的操作。
可能看起来像这样:
routes.php文件
Route::auth();
$this->get('b_login', 'Auth\BusinessAuthController@showLoginForm');
$this->post('b_login', 'Auth\BusinessAuthController@login');
认证/ AuthController.php
...
use AuthenticatesAndRegistersUsers;
protected $redirectPath = '/home';
// do some other stuff
...
认证/ BusinessAuthController.php
...
use AuthenticatesAndRegistersUsers;
protected $redirectPath = '/home-business';
// for checking $user->is_business_user == 1 while attemping login
protected function getCredentials(Request $request){
$credentials = $request->only($this->loginUsername(), 'password');
$credentials['is_business_user'] = 1;
return $credentials;
}
// do some other stuff
...