Sunday, February 11, 2018

SQLSTATE[HY000]: General error – create an account - development

SQLSTATE[HY000]: General error – create an account

Im using laravel auth. In the register page the user needs to fill in the name, surname, email and password to create an account. Later the user can edit his profile account and insert more info like address, city, zipcode, etc, but to create account its just necessary name, surname, email and password.

Im structuring this above logic with the code below using the laravel auth, but Im getting an error after filling the form and click in “Create Account”:

SQLSTATE[HY000]: General error: 1364 Field ‘facebook_id’ doesn’t have a default value (SQL: insert into users (name, email, password, updated_at, created_at) values (…)

Do you know what is the error in the code below?

Routes:

Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');

User table migration:

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('facebook_id')->unique();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('phone');
            $table->dateTime('dateRegister');
            $table->string('address');
            $table->string('zipCode');
            $table->string('city');
            $table->timestamps();
        });
    }
   }

User model:

   class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'name', 'email', 'password', 'facebook_id', ''
    ];

    protected $hidden = [
        'password',
    ];
   }

RegisterController:

<?php

namespace AppHttpControllersAuth;

use AppUser;
use AppHttpControllersController;
use IlluminateSupportFacadesValidator;
use IlluminateFoundationAuthRegistersUsers;

class RegisterController extends Controller
{
    use RegistersUsers;
    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest');
    }
    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',
        ]);
    }

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),

        ]);
    }

}



from Laravel Questions and Answers https://laravelquestions.com/laravel/sqlstatehy000-general-error-create-an-account/
via Lzo Media

No comments:

Post a Comment