WallyJ
2 months ago
125
2
Laravel

Create New User - Only a few fields reach the DB

Posted 2 months ago by WallyJ

I am editing the create.blade.php and UserController from the original Auth from Laravel to add more fields.

I adjusted the form and the Controller. It creates the user, but only puts the name, email, and password into the DB.

Here's my controller:

    {

        $flashmessage = "New User Has Been Created";
       
        $names = explode(' ', Input::get('name'), 2);
        $firstname = $names[0];
       
        $phonenumber = Input::get('phone');
       
        $phonelast4 = substr ($phonenumber, -4);
       
        $newusername = $firstname.$phonelast4;
       
        $usercheck = DB::table('users')->where('username', '=', $newusername)->count();
       
        if ($usercheck > 0)  {
           // user does exist
           while (DB::table('users')->where('username', '=', $newusername)->count() > 0) {
       
            $phonelast4++;
       
            $newusername = $firstname.$phonelast4;
       
           }

           $flashmessage = "New User Has Been Created - The expected username was taken so this user's username is " . $newusername;
       
        }
       
        $request->merge(['username' => $newusername]);
        $request->merge(['password' => Hash::make($request->password)]);

        // return $request->all();
        // die();

        $user = User::create($request->all());

        return redirect()->route('edituser', ['user' => $user])->with('success', $flashmessage);

    }

As you can see, I tried "return $request->all(); which showed me all of the values entered into the form, but they don't end up in the db.

Please sign in or create an account to participate in this conversation.