1
votes

This is the errorr:

Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (SQL: select count(*) as aggregate from users where `` = [email protected])

My Resgister Controller:

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']),
    ]);
}

} My user table migration:

<?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**
<!DOCTYPE html>
<html>

<head>

</head>

<body>
    <div class="accountbg"></div>
    <div class="wrapper-page">
        <div class="panel panel-color panel-primary panel-pages">
            <div class="panel-body">
                <h3 class="text-center m-t-0 m-b-30">
                    <span class=""><img src="{{ asset('/') }}admin/assets/images/
                    logo_dark.png" alt="logo" height="32"></span>
                </h3>
                <h4 class="text-muted text-center m-t-0"><b>{{ __('Sign Up') }}</b></h4>
                <form class="form-horizontal m-t-20" method="POST" action="{{ route('register') }}" autocomplete="on">
                @csrf
                    <div class="form-group">
                        <div class="col-xs-12">
                            <input class="form-control" name="name" required="required" type="text" placeholder="Username"
                            value="{{ old('name') }}" autocomplete="off" autofocus/>

                            @error('name')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-12">
                            <input class="form-control" name="email"
                            value="{{ old('email') }}" required="required" type="email" placeholder="Email" autocomplete="email"/>
                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-12">
                            <input class="form-control" name="password" required="required" type="password"
                            placeholder="Password" autocomplete="off"/>
                            @error('password')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-12">
                            <input class="form-control" name="password_confirmation" required="required" type="password"
                            placeholder="Confirm password" autocomplete="password"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-12">
                            <div class="checkbox checkbox-primary">
                                <input id="checkbox-signup" name="term" type="checkbox"
                                value="{{ old('term') ? 'checked' : '' }}">
                                <label for="checkbox-signup"> {{ __('I accept') }} <a href="{{ route('register') }}">
                                    {{ __('Terms and Conditions') }}
                                </a> </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group text-center m-t-20">
                        <div class="col-xs-12">
                            <button class="btn btn-primary w-md waves-effect waves-light" type="submit">{{ __('Register') }}</button>
                        </div>
                    </div>
                    <div class="form-group m-t-30 m-b-0">
                        <div class="col-sm-12 text-center"> <a href="{{ route('login') }}"
                            class="text-muted">{{ __('Already have account?') }}</a></div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</body>
</html>
1
Hello. What part of the code is this query coming from - select count(*) as aggregate from usersmanishk
Hlw, I am adding all outher code of my project... please cheak it again.Abu Based Jibon
Get rid of extra comma in your validation rule. 'unique:users,' Voting for closure as typo.miken32
Opps! thanks 😍 Really am spanding about 5hours to fix it but am not see that before. (damn) @miken32Abu Based Jibon

1 Answers

0
votes

You should write the unique rule like so, you had a comma in it.

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

An great alternative is to use the validation rule class for this, then you will get parameter typehinting and know what options there is.

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