In one of my Laravel 5.6 applications, I need to add a few more fields in the default registration form.
So I’ve added only one field to test [phone_no] in the default registration form registration.blade.php, and also add phone_no RegisterController, but when I click on the register button it shows the following errors:
"SQLSTATE[HY000]: General error: 1364 Field 'phone_no' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (Jahid Hossain, jahid.cse18@gmail.com, $2y$10$wYg6jAihCz.v09PUXngF/ekjNvZgxb4Rq4GI3i.glfzXt37oGnbSO, 2018-04-20 06:24:27, 2018-04-20 06:24:27))
So here is the migration file code:
public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->string('status')->default('active'); $table->string('created_by')->default('SYSTEM'); $table->string('modified_by'); $table->string('phone_no'); $table->rememberToken(); $table->timestamps(); }); }
And here is the code of RegisterController:
protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'created_by' => $data['email'], 'phone_no' => $data['phone_no'], ]); }
So I think I am missing something. Can anyone tell me how can I add one/more fields in the Laravel 5.6 default registration form and save those field successfully…
- Thanks
Advertisement
Answer
Please add your custom field in below way.
In your model add the your custom field in protected $fillable=['name', 'email', 'password', 'created_by', 'phone_no']
in your model