为什么在我提交注册表时给我错误

时间:2019-11-14 22:40:33

标签: php laravel laravel-validation

这是错误者:

Illuminate \ Database \ QueryException SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“(SQL:从import React from 'react'; import { Navbar, Nav } from 'react-bootstrap' class NavigationBar extends React.Component { render() { return ( <div> <Navbar bg="dark" variant ="dark"> <Nav className="mr-auto"> <Navbar.brand href="#home">Tom Abarbanel</Navbar.brand> <Nav.Link href="#About">About</Nav.Link> <Nav.Link href="#Experience">Experience</Nav.Link> <Nav.Link href="#Skills">Skills</Nav.Link> <Nav.Link href="#Projects">Projects</Nav.Link> </Nav> </Navbar> </div> ); } }; export default NavigationBar; 中选择count(*)作为聚合,其中“ = user@email.com)

我的Resgister控制器:

users

} 我的用户表迁移:

use RegistersUsers;

/**
 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo = '/';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest');
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users,'],
        'password' => ['required', 'string', 'min:6', 'confirmed'],
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ]);
}
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email', 150)->unique();
            $table->string('password');
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('number')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

**My User Model**
<?php

namespace App;

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

class User extends Authenticatable
{
    use Notifiable;

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

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

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

**My View File Register.blade.php**

1 个答案:

答案 0 :(得分:0)

您应该这样编写独特的规则,其中包含逗号。

'email' => ['unique:users',],

一个很好的选择是为此使用验证规则类,然后您将获得参数类型提示并知道有哪些选项。

'email' => [new Unique('users'),],