Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel未将自定义值保存到用户表格_Php_Mysql_Database_Laravel - Fatal编程技术网

Php laravel未将自定义值保存到用户表格

Php laravel未将自定义值保存到用户表格,php,mysql,database,laravel,Php,Mysql,Database,Laravel,我正在使用Laravel5.4和MySql数据库。 我正在尝试扩展我的用户表,并在注册用户时保存更多信息,但该值似乎无法保存到数据库中 以下是我的迁移(仅使用up方法): 我已将mobile_phone元素放入$filleble数组中: protected $fillable = [ 'name', 'email', 'password', 'mobile_phone' ]; 并将该值添加到app/Http/Controllers/Auth/RegisterController.php

我正在使用Laravel5.4和MySql数据库。 我正在尝试扩展我的用户表,并在注册用户时保存更多信息,但该值似乎无法保存到数据库中

以下是我的迁移(仅使用up方法):

我已将mobile_phone元素放入$filleble数组中:

protected $fillable = [
    'name', 'email', 'password', 'mobile_phone'
];
并将该值添加到app/Http/Controllers/Auth/RegisterController.php

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

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'mobile_phone' => $data['mobile_phone'],
        'password' => bcrypt($data['password']),
    ]);
}
将输入添加到表单中:

<div class="form-group{{ $errors->has('mobile_phone') ? ' has-error' : '' }}">
    <label for="mobile_phone" class="col-md-4 control-label">Mobile</label>
    <div class="col-md-6">
        <input id="mobile_phone" type="text" class="form-control" name="mobile_phone" value="{{ old('mobile_phone') }}" required>

        @if ($errors->has('mobile_phone'))
            <span class="help-block">
                <strong>{{ $errors->first('mobile_phone') }}</strong>
            </span>
        @endif
    <div>
</div>
当我将该值设置为false时,它会保存新用户,但mobile_phone列为空

我错过了什么


非常感谢
dd
您的
$data
并查看您在那里得到了什么。尝试
composer dumpautoload
,并刷新您的迁移。
composer dumpautoload
成功。谢谢
<div class="form-group{{ $errors->has('mobile_phone') ? ' has-error' : '' }}">
    <label for="mobile_phone" class="col-md-4 control-label">Mobile</label>
    <div class="col-md-6">
        <input id="mobile_phone" type="text" class="form-control" name="mobile_phone" value="{{ old('mobile_phone') }}" required>

        @if ($errors->has('mobile_phone'))
            <span class="help-block">
                <strong>{{ $errors->first('mobile_phone') }}</strong>
            </span>
        @endif
    <div>
</div>
SQLSTATE[HY000]: General error: 1364 Field 'mobile_phone' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (Loki, loki@loki.com, $2y$10$9Y1HtCIHLThiwRNklz5WKOT7Y/B0Prpvb9yMJRmlGePhPrLDNFDme, 2017-07-06 19:32:09, 2017-07-06 19:32:09))