Laravel字段没有默认值

时间:2019-11-28 10:58:49

标签: sql laravel forms submit

我想注册,但是提交后出现此错误

  

一般错误:1364字段“电子邮件”没有默认值

我通过“迁移”列FirmanameEmail添加了内容,然后将其添加到RegisterController中, 但是当我提交添加用户时,它告诉我字段电子邮件没有默认值

这是我的表格

<form method="POST" action="{{ route('register') }}">
                                @csrf

                                <div class="form-group row">
                                    <label for="employeenumber"
                                           class="col-md-4 col-form-label text-md-right">{{ __('Leveranciersnummer') }}</label>

                                    <div class="col-md-6">
                                        <input id="employeenumber" type="text"
                                               class="form-control @error('employeenumber') is-invalid @enderror"
                                               name="employeenumber"
                                               value="{{ old('employeenumber') }}" required>

                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="firmaname"
                                           class="col-md-4 col-form-label text-md-right">{{ __('Firmanaam') }}</label>

                                    <div class="col-md-6">
                                        <input id="firmaname" type="text"
                                               class="form-control @error('firmaname') is-invalid @enderror"
                                               name="firmaname"
                                               value="{{ old('firmaname') }}" required>

                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="name"
                                           class="col-md-4 col-form-label text-md-right">{{ __('Voornaam') }}</label>

                                    <div class="col-md-6">
                                        <input id="name" type="text"
                                               class="form-control @error('name') is-invalid @enderror" name="name"
                                               value="{{ old('name') }}" required autocomplete="name" autofocus>

                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label for="lastname"
                                           class="col-md-4 col-form-label text-md-right">{{ _('Achternaam') }}</label>

                                    <div class="col-md-6">
                                        <input id="lastname" type="text"
                                               class="form-control @error('lastname') is-invalid @enderror"
                                               name="lastname"
                                               value="{{ old('lastname') }}" required autocomplete="lastname" autofocus>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="email"
                                           class="col-md-4 col-form-label text-md-right">{{ __('Email') }}</label>

                                    <div class="col-md-6">
                                        <input id="email" type="email"
                                               class="form-control @error('email') is-invalid @enderror"
                                               name="email"
                                               value="{{ old('email') }}" required>

                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="password"
                                           class="col-md-4 col-form-label text-md-right">{{ __('Wachtwoord') }}</label>

                                    <div class="col-md-6">
                                        <input id="password" type="password"
                                               class="form-control @error('password') is-invalid @enderror"
                                               name="password" required autocomplete="new-password">

                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label for="password-confirm"
                                           class="col-md-4 col-form-label text-md-right">{{ __('Wachtwoord Bevestigen') }}</label>

                                    <div class="col-md-6">
                                        <input id="password-confirm" type="password" class="form-control"
                                               name="password_confirmation" required autocomplete="new-password">
                                    </div>
                                </div>

                                <div class="form-group row mb-0">
                                    <div class="col-md-6 offset-md-4">
                                        <button type="submit" class="btn btn-secondary">
                                            {{ __('Registreer') }}
                                        </button>
                                    </div>
                                </div>
                            </form>

这是我的控制器

protected function create(array $data)
    {
        return User::create([
            'employeenumber' => $data['employeenumber'],
            'firmaname' => $data['firmaname'],
            'name' => $data['name'],
            'lastname' => $data['lastname'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}

所以我不知道为什么会出现这个错误

1 个答案:

答案 0 :(得分:1)

确保在您的用户模型中定义了fillable变量。如果未声明,则添加它。所以一定是这样。

/**
 * The attributes that are mass assignable.
 *
 * @var array
*/
protected $fillable = [
    'empployeenumber', 'firmaname', 'name', 'lastname', 'email', 'password'
];