How can I make a registration form that has both register and login sections on the same page in Laravel 7?

  laravel

I’m working on my application using Laravel 7, I have a registration form and login form in the same page. The first section of the form is mandatory for both "new" and "returning" customers.
If the customer is new, they are required to fill their personal details in order to create an account. (That part is working well). The second part is the Login form for existing customers, who are also required to fill the mandatory part of the form.

The challenge is; I’m not able to access the data entered in the first part of the form and use it for the second part (Login section).
NB: For both registration part and login part, I’m redirecting the users to a "preview" page where they check their details and then submit.
Please help.

My Register Controller:

public function __construct()
    {
        $this->middleware('guest');
    }

    // Showing a Registration Form to User

    public function create()
    {
        
        $categories = Category::all();
      
        
        return view('auth.client.register',compact('categories'));
    }


    // Validating the User

    public function store(Request $request)
    {
        $request->validate([
            'first_name'            => 'required|string|max:255',
            'last_name'             => 'required|string|max:255',
            'telephone_number'      => 'required|digits:10',
            'email'                 => 'required|string|email|max:255|unique:users','regex:/^[w-.+][email protected][a-zA-Z0-9.-]+.[a-zA-z0-9]{2,6}$/',
            'password'              => 'required|string|min:6|confirmed',
            'password_confirmation' => 'required',
            'region'                => 'required|string',
            'description'           => 'required|string|max:2500',
            'start_date'            => 'required|date',
            'client_region'         => 'string|max:500',
            'client_category'       => 'integer|max:255',
        ]);

      // Creating the Client inside Users Table

        $user = User::create([
                    'first_name'        => $request->first_name,
                    'last_name'         => $request->last_name,
                    'telephone_number'  => $request->telephone_number,
                    'email'             => $request->email,
                    'password'          => Hash::make($request->password),

        ]);
}

My Controller for Previewing information before submitting:

public function confirmation(Request $request)

    {

        $categories = Category::all();

        $request->validate([
            'first_name'            => 'required|string|max:255',
            'last_name'             => 'required|string|max:255',
            'telephone_number'      => 'required|digits:10',
            'email'                 => 'required|string|email|max:255|unique:users','regex:/^[w-.+][email protected][a-zA-Z0-9.-]+.[a-zA-z0-9]{2,6}$/',
            'password'              => 'required|string|min:6|confirmed',
            'password_confirmation' => 'required',
            'region'                => 'required|string',
            'description'           => 'required|string|max:2500',
            'start_date'            => 'required|date',
            'client_region'         => 'string|max:500',
            'client_category'       => 'integer|max:255',
        ]);

        
        $data = $request->all();
        return view('auth.client.preview', compact('categories', 'data'));
}

enter image description here

enter image description here

Source: Laravel

Leave a Reply