0

In a laravel app I had run the command

php artisan make:auth

and a laravel register form created successfully.

In mysql users' table I had added a proffession field of varchar datatype column and 190 length.

And I updated Auth/register.blade.php page to the following

register.blade.php

<div class="form-group">
<label for="proffession" class="col-md-4 control-label"> proffession </label>
 <div class="col-md-6">
 <input id="proffession" type="text" class="form-control" name="porffession" 
 value="{{ old('proffession') }}" required>
 </div>
 </div>

My RegisterController.php class

    protected function validator(array $data)
        {
          return Validator::make($data, [
               'name' => 'required|string|max:255',
               'phone' => 'required|string|max:255',
              'email' => 'required|string|email|max:255|unique:users',
               'password' => 'required|string|min:6|confirmed',
         ]);
    }

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
             'phone' => $data['phone'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

but when I click the submit button the proffession column value is always null although a new user added.

5
  • 1
    Where's your controller code? Commented Mar 28, 2018 at 12:17
  • Automatically I am drawn to: name="porffession" typo.. surely should be name="proffession" no? Commented Mar 28, 2018 at 12:17
  • I have updated my answer for you Webdev. Commented Mar 28, 2018 at 12:25
  • @Option It seems the problem from mission of proffession RegistereController.php Commented Mar 28, 2018 at 12:28
  • Take a look at my answer webdev. Commented Mar 28, 2018 at 12:28

1 Answer 1

1

Looking at your view code I can see that name="porffession" should surely be name="proffession"

Change your controller code from:

return User::create([
            'name' => $data['name'],
             'phone' => $data['phone'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);

to:

return User::create([
    'name' => $data['name'],
    'phone' => $data['phone'],
    'email' => $data['email'],
    'password' => bcrypt($data['password']),
    'proffession' => $data['proffession'],
]);

and fix the typo as mentioned above.

Also within the User.php model add proffession to the $fillable if you haven't already.

Sign up to request clarification or add additional context in comments.

8 Comments

should I change this also ? return Validator::make($data, [ 'name' => 'required|string|max:255', 'phone' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', ]);
@WebDev, For testing purposes I wouldn't touch verification for now. Get it working first and then you can add it after.
'profession' => $request->get('profession') where this statement to be?
@WebDev, I have revised and edited. I added that initially because you had no controller code. I have now removed. Replace the block coding as given above.
@webdev, my mistake sorry.. I put profession where as you are using proffession I have adjusted the code block accordingly. Please edit the code block with the updated version and then retry
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.