0

I'm trying to build a simple registration form with some fields in laravel 5.3 I'm getting insert error while doing so, following is the screenshot:

enter image description here

Following is my blade file:

@extends('admin.authlayouts')

@section('content')
<!-- Registration content -->
<div class="col-xs-12 login-content reg-content">
    <span class="text-center">Register to get your account</span>
    <div class="col-xs-12 login-form">
        <form role="form" method="POST" action="{{ url('/memberregister') }}">
          {{ csrf_field() }}

            <label>Enter your personal details below.</label>
            <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                <label class="sr-only" for="full-name">Full name</label>
                <input type="text" name="name" id="name" value="{{ old('name') }}" placeholder="Full name" class="input-field full-name form-control" required autofocus>
              @if ($errors->has('name'))
                <span class="help-block">
                    <strong>{{ $errors->first('name') }}</strong>
                </span>
            @endif
            </div>
            <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                <label class="sr-only" for="email">Email</label>
                <input id="name" type="email" name="email" value="{{ old('email') }}" placeholder="Email" class="input-field email form-control" required>
              @if ($errors->has('email'))
                <span class="help-block">
                    <strong>{{ $errors->first('email') }}</strong>
                </span>
            @endif
            </div>
            <div class="form-group{{ $errors->has('address') ? ' has-error' : '' }}">
                <label class="sr-only" for="address">Address</label>
                <input type="text" name="address" id="address" value="{{ old('address') }}" placeholder="Address" class="input-field address form-control" required>
              @if ($errors->has('address'))
                <span class="help-block">
                    <strong>{{ $errors->first('address') }}</strong>
                </span>
            @endif
            </div>
            <div class="form-group{{ $errors->has('city') ? ' has-error' : '' }}">
                <label class="sr-only" for="city">City/Town</label>
                <input type="text" name="city" id="city" value="{{ old('city') }}" placeholder="City/Town" class="input-field city form-control" required>
              @if ($errors->has('city'))
                <span class="help-block">
                    <strong>{{ $errors->first('city') }}</strong>
                </span>
            @endif
            </div>
            <div class="form-group{{ $errors->has('country') ? ' has-error' : '' }}">
                <label class="sr-only" for="country">Country</label>
                <select name="country" id="country" class="input-field country form-control">
                    <option value="">Select a country</option>
                  <option value="India">India</option>
                </select>
              @if ($errors->has('country'))
                <span class="help-block">
                    <strong>{{ $errors->first('country') }}</strong>
                </span>
            @endif
            </div>
            <label>Enter your new account details below.</label>
            <div class="form-group{{ $errors->has('country') ? ' has-error' : '' }}">
                <label class="sr-only" for="username">Username</label>
                <input id="username" type="text" name="username" value="{{ old('city') }}" placeholder="Username" class="input-field username form-control">
              @if ($errors->has('username'))
                <span class="help-block">
                    <strong>{{ $errors->first('username') }}</strong>
                </span>
            @endif
            </div>
            <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                <label class="sr-only" for="password">Password</label>
                <input type="password" name="password" placeholder="Password" class="input-field password form-control">
              @if ($errors->has('password'))
                <span class="help-block">
                    <strong>{{ $errors->first('password') }}</strong>
                </span>
            @endif
            </div>
            <div class="form-group">
                <label class="sr-only" for="retype-password">Confirm Password</label>
                <input type="password" name="password_confirmation" id="password-confirm" placeholder="Retype Password" class="input-field re-password form-control">
            </div>
            <div class="form-group">
                <label><input type="checkbox" name="" id="remember-check"> I agree to the  Terms & Conditions & Privacy Policy</label>
            </div>
            <input type="submit" value="Sign up" class="btn btn-success pull-right">
        </form>
    </div>
</div>
@endsection                    

Following is my Controller:

public function memberregister(Request $request)
{
  $this->validate($request, User::$register_validation_rules);
  $data = $request->only('name', 'email', 'password', 'username', 'address', 'city', 'is_admin', 'contact');
  $data['password'] = bcrypt($data['password']);
  $data['is_admin'] = 0;
  $user = User::Create($data);
  if($user){
    \Auth::login($user);
    return redirect('member.dashbaord');
  }

  return back()->withInput();
}

Following is my user model:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'contact', 'address', 'city', 'country', 'username', 'bankname', 'bankaddress', 'ifsccode', 'accountnumber', 'is_admin'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public static $login_validation_rules = [
      'username' => 'required|exists:user',
      'password' => 'required'

    ];

    public static $register_validation_rules = [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'username' => 'required|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
//             'contact_number' => 'required',
            'address' => 'required|max:255',
            'city' => 'required|max:255',
//             'state' => 'required|max:255',
//             'country' => 'required|max:255'

    ];

}

Please help me out.

Thanks.

6
  • Looks like you have "country" in your schema and it is not nullable() and/or has no default(), and you don't provide that value from your form. Fix as appropriate (make it nullable, give it a default, add a country field to the form). Commented Dec 1, 2016 at 3:52
  • @markdwhite Yes, I also think that. Commented Dec 1, 2016 at 3:54
  • Check on your migration file for your country attribute $table->string('country')->nullable(); or you can check directly allow_null on phpmyadmin as well Commented Dec 1, 2016 at 3:58
  • @markdwhite : But I'm filling out the country details. Is there any problem in form? Commented Dec 1, 2016 at 4:12
  • @NitishKumar - I see no reference to "country" in your memberregister() method at all Commented Dec 1, 2016 at 4:14

3 Answers 3

2

Looks like you have "country" in your schema and it is not nullable() and/or has no default(), and you don't provide that value from your form. Fix as appropriate (make it nullable, give it a default, add a country field to the form).

I see no reference to "country" in your memberregister() method at all

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

Comments

2

In your User model, $fillable array contains country column. But you are trying to create new record without inserting any value for county column.

So all you have to define a default value for country column while creating a record in users table.

In your users migration file , set country column to nullable.

$table->string('country')->nullable();

2 Comments

But I'm trying to insert country value through select box in the form.
select box for country's value has name attribute country in your form, just insert country in following line , $request->only('name', 'email', 'password', 'username', 'address', 'city', 'is_admin', 'contact');
1

Check the following line

$data = $request->only('name', 'email', 'password', 'username', 'address', 'city','country', 'is_admin', 'contact');

There is no country in request. You need to add country also.

Comments

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.