How to register without email with laravel auth

852 views Asked by At

I want make register form by number, name, password with Laravel auth.

So I change username method in LoginController.php and validate method ,create method in RegisterController.php like following code.

But always show error

SQLSTATE[HY000]: General error: 1364 Field 'email' doesn't have a default value

LoginController

    public function username()
    {
        return 'number';
    }

RegisterController

    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'number' => ['required'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
            'password_confirmation' => ['required'],
        ]);
    }

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

I spent 2day for find registration customize authentication but I only see login customize.

I finded only one about registration customize. But this page don't show solution.

https://laracasts.com/discuss/channels/laravel/user-registration-without-email?page=1

please help me.

1

There are 1 answers

0
aurawindsurfing On BEST ANSWER

Your User Model has email field that it:

  1. requires
  2. does not have default value when you try to create new user.

Go to your migrations create_users_table, and edit:

$table->string('email')->unique();

to

$table->string('email')->nullable();

But this is bad idea in my opinion, how will you identify those users later on? How will you let them reset their passwords?