Recent Topics

Not storing the data into database If I add few more input fields to signup form



  • Hi,

    I have added few more input fields to signup page like phone, house_no, street, etc. Later I have added these fields to validate method in RegistrationController.php file and then I have created few more columns in database for which I have created sign up page like phone, house_no, street, etc. The problem is only phone number only storing along with first_name, last_name, etc. in database but not storing house_no, street, etc. Please find below is the code for controller and see the screenshot for signup page, thank you.

      public function create(Request $request)
        {
            $request->validate([
                'first_name' => 'string|required',
                'last_name' => 'string|required',
                'phone' => 'string|required',
                'house_no' => 'string|required',
                'street' => 'string|required',
                'area' => 'string|required',
                'city' => 'string|required',
                'pincode' => 'string|required',
                'landmark' => 'string|required',
                'email' => 'email|required|unique:customers,email',
                'password' => 'confirmed|min:6|required',
            ]);
    
            $data = request()->input();
         
            $data['password'] = bcrypt($data['password']);
    
            $data['channel_id'] = core()->getCurrentChannel()->id;
    
            if (core()->getConfigData('customer.settings.email.verification')) {
                $data['is_verified'] = 0;
            } else {
                $data['is_verified'] = 1;
            }
    
            $data['customer_group_id'] = $this->customerGroup->findOneWhere(['code' => 'general'])->id;
    
            $verificationData['email'] = $data['email'];
            $verificationData['token'] = md5(uniqid(rand(), true));
            $data['token'] = $verificationData['token'];
    
            Event::fire('customer.registration.before');
    
            $customer = $this->customer->create($data);
    
            Event::fire('customer.registration.after', $customer);
    
            if ($customer) {
                if (core()->getConfigData('customer.settings.email.verification')) {
                    try {
                        Mail::queue(new VerificationEmail($verificationData));
    
                        session()->flash('success', trans('shop::app.customer.signup-form.success-verify'));
                    } catch (\Exception $e) {
                        session()->flash('info', trans('shop::app.customer.signup-form.success-verify-email-unsent'));
                    }
                } else {
                    session()->flash('success', trans('shop::app.customer.signup-form.success'));
                }
    
                return redirect()->route($this->_config['redirect']);
            } else {
                session()->flash('error', trans('shop::app.customer.signup-form.failed'));
    
                return redirect()->back();
            }
        }
    

    screencapture-localhost-bagisto-socialite-master-customer-register-2019-07-17-10_23_30.png



  • Hi @Keerthi

    Did you mentioned your fillable attribute in customer model ?

     protected $fillable = ['first_name', 'channel_id', 'last_name', 'gender', 'date_of_birth', 'email', 'phone', 'password', 'customer_group_id', 'subscribed_to_news_letter', 'is_verified', 'token', 'notes', 'status'];
    

    If not then please do it & then check.

    Thanks



  • Hi,

    Thank you, now It is working fine. Actually I forgot to update in model, once again thank you so much.


Log in to reply