Tuesday, April 11, 2017

Laravel create user statement doesn't store specific columns

I am using Laravel version 5.4 . I have a table called Users and each user has the below columns :

  Schema::create('users', function (Blueprint $table) {

            $defaultValue = 0;

            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('facebook_id')->unique();
            $table->string('avatar');
            $table->integer('newsletter')->default($defaultValue); // <-
            $table->bigInteger('category_1')->default($defaultValue); // <-
            $table->bigInteger('category_2')->default($defaultValue); // <-
            $table->bigInteger('category_3')->default($defaultValue); // <-
            $table->timestamp('unlocked_tip_of_category_1_at')->nullable();
            $table->timestamp('unlocked_tip_of_category_2_at')->nullable();
            $table->timestamp('unlocked_tip_of_category_3_at')->nullable();
            $table->rememberToken();
            $table->timestamps();
        });

The problem is that when i use the function to create a user category_1, category_2 and category_3 don't take the new value which is 1.

After taking auth from facebook i use the below to store user's information :

 return User::create([
            'name' => $facebookUser->name,
            'email' => $facebookUser->email,
            'facebook_id' => $facebookUser->id,
            'avatar' => $facebookUser->avatar,
            'newsletter' => 0,
            'category_1' => 1,
            'category_2' => 1,
            'category_3' => 1,
        ]);

For example name changes to facebook user's name. Also i tried changing

'name' => $facebookUser->name,

to

'name' => $facebookUser->name . " HEY",

Which successfuly stored the name and + " HEY" at the end. (Just to be sure that this runs).

Categories are bigInteger that means a bigint(20) type. I am thinking something happens with the default values which i've set it to 0.

Any ideas? If you need any more information please let me know.

  • From what i am trying to accomplish the best way to solve this is to change the $defaultvalue to 1, but i don't understand why this doesn't work.


via Antonis Tsimourtos

Advertisement