简体   繁体   中英

How to create or customize registration authentication in two step using laravel

I'm just new to Laravel. What I want is to enhance my registration authentication in laravel having an environment of vagrant homestead.For example on the first page of the form the user will provide his name and email and there will be a button of "Next" which will lead to a second form. From the second form, there will be a password field to fill in before clicking the "Register" button.

I'm having some troubles to do that. Any help would be much appreciated.

Define 2 functions in your controller for each step, and each page will post to its respective function

public function step1(Request $request)
{
    ... //whatever you do before

    session(['name' => $request->name]);
    session(['email' => $request->email]);
    return redirect()->to('step2');
}

Your second page could post to a function like this

public function step2(Request $request)
{
    ...//whatever you do 
    $name = session('name');
    $email = session('email');

    $password = $request->password;

    //Do registration

    /**
    * Removed saved items from session
    * Important to remove after registration, just in case the user refreshes the page before registration is over
    */
    $request->session()->forget('name');
    $request->session()->forget('email');

    //Finish with whatever you (email, confirmation, etc.)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM