Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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_Registration - Fatal编程技术网

Php 如何在我的新Laravel项目上修复用户注册?

Php 如何在我的新Laravel项目上修复用户注册?,php,mysql,database,laravel,registration,Php,Mysql,Database,Laravel,Registration,我创建了一个新的Laravel项目。我使用了标准的php artisan make:auth 并生成所需的文件和连接。我在phpMyAdmin中创建了表,并在.env文件中连接了这两个表。我检查了连接和迁移,一切正常 问题是,当我想创建一个新用户并输入所有注册数据时,first_name和last_name字段显然无法读取,我会收到一个错误,说“first name字段是必需的”。last name也是如此。密码或电子邮件没有错误 首先,这里是RegisterController: protec

我创建了一个新的Laravel项目。我使用了标准的
php artisan make:auth
并生成所需的文件和连接。我在phpMyAdmin中创建了表,并在.env文件中连接了这两个表。我检查了连接和迁移,一切正常

问题是,当我想创建一个新用户并输入所有注册数据时,
first_name
last_name
字段显然无法读取,我会收到一个错误,说“first name字段是必需的”。last name也是如此。密码或电子邮件没有错误

首先,这里是RegisterController:

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

protected function create(array $data)
{
    return User::create([
        'first_name' => $data['first_name'],
        'last_name' => $data['last_name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}
register.blade.php:

<form class="form-horizontal" role="form" method="POST" action="{{   route('register') }}">
    {{ csrf_field() }}

    <div class="form-group{{ $errors->has('first_name') ? ' has-error' : '' }}">
        <label for="first_name" class="col-md-4 control-label">First Name</label>

        <div class="col-md-6">
            <input id="first_name" type="text" class="form-control" first_name="first_name" value="{{ old('first_name') }}" required autofocus>

            @if ($errors->has('first_name'))
                <span class="help-block">
                    <strong>{{ $errors->first('first_name') }}</strong>
                </span>
            @endif
        </div>
    </div>

    <div class="form-group{{ $errors->has('last_name') ? ' has-error' : '' }}">
        <label for="last_name" class="col-md-4 control-label">Last Name</label>

        <div class="col-md-6">
            <input id="last_name" type="text" class="form-control" last_name="last_name" value="{{ old('last_name') }}" required autofocus>

            @if ($errors->has('last_name'))
                <span class="help-block">
                    <strong>{{ $errors->first('last_name') }}</strong>
                </span>
            @endif
        </div>
    </div>
我查看了论坛和Laravel文档,但没有发现错误。

问题在于:

<input id="first_name" type="text" class="form-control" first_name="first_name" value="{{ old('first_name') }}" required autofocus>

这里不是
name=“first\u name”
,而是
first\u name=“first\u name”
。做得合适,然后再试一次。同样适用于
last\u name=“last\u name”

说明:

在服务器端,使用元素的
name
属性获取元素值。但是在您的情况下,
name
属性丢失,这会导致验证失败,并显示需要名字段
last\u name

<input id="first_name" type="text" class="form-control" first_name="first_name" value="{{ old('first_name') }}" required autofocus>