我想在注册成功后自动登录并重定向到编辑个人资料页面。我尝试了以下代码,但没有按我的意愿工作
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = '/edit_profile';
public function __construct()
{
$this->middleware('guest');
}
public function createUser(Request $request)
{
$this->validate($request , [
'firstName' => 'required',
'lastName' => 'required',
'displayName' => 'required',
'email' => 'required |email',
'password' =>'required ',
'gender' =>'required',
'day' =>'required|max:2',
'month' =>'required|max:2',
'year' =>'required|max:4',
]);
$email=$request->input('email');
$password=$request->input('paasword');
$dob=$request->input('day').'-'.$request->input('month').'-'.$request->input('year');
$request->request->add(['dob'=>$dob]);
$request->request->add(['password'=>bcrypt($request->input('password'))]);
$data = User::create($request->except(['_token', 'submit', 'day','month','year', 'confirm_password' ,'dayInWeek']));
Auth::login($data);
}
}
路线
Route::get('/', 'PageController@login');
Route::get('/home', 'HomeController@index');
Route::group( ['middleware' => 'auth' ], function()
{
Route::get('main', 'PageController@main');
Route::get('browse', 'PageController@browse');
Route::get('pickngo', 'PageController@pickngo');
Route::get('edit_profile', 'PageController@profile');
}
答案 0 :(得分:2)
只需修改您的身份验证登录,就像
一样if(Auth::login($data)) {
return redirect('/edit_profile');
}
else
{
return redirect()->back();
}
答案 1 :(得分:2)
通过传递用户ID来使用Laravel loginUsingId($ id)函数。
$data = User::create($request->except(['_token', 'submit', 'day','month','year', 'confirm_password' ,'dayInWeek']));
Auth::loginUsingId($data->id);
答案 2 :(得分:1)