jzmwebdevelopment's avatar

Fatal error: Call to undefined method

Why would I be getting Fatal error: Call to undefined method CreateUsers::increments() When I run php artisan migrate

Users:

<?php

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

class CreateUsers extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('user_id');
            $table->string('f_name');
            $table->string('l_name');
            $table->string('gender');
            $table->date('dob');
            $table->string('company_name');
            $table->string('email')->unique();
            $table->string('password');
            $table->increments('landline');
            $table->increments('mobile');
            $table->increments('activated');
            $this->increments('social_login');
            $table->timestamp('last_login');
            $table->rememberToken();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}
0 likes
3 replies
freel's avatar

remove this: $table->increments('user_id'); it should generate automatically increments if you not disabled in your model.

tykus's avatar
tykus
Best Answer
Level 104
        Schema::create('users', function (Blueprint $table) {
            $table->increments('user_id');
            $table->string('f_name');
            $table->string('l_name');
            $table->string('gender');
            $table->date('dob');
            $table->string('company_name');
            $table->string('email')->unique();
            $table->string('password');
            $table->increments('landline');
            $table->increments('mobile');
            $table->increments('activated');
            $this->increments('social_login');   // <<<< HERE you are referring to $this, not $table
            $table->timestamp('last_login');
            $table->rememberToken();
        });

As an aside, you appear to be using increments inappropriately - in fact, Laravel probably cannot handle this. Try the following:

  • landline (string) $table->string('landline');
  • mobile (string) $table->string('mobile');
  • activated (boolean), $table->boolean('activated');
  • social_login (string) probably? $table->string('social_login');.
1 like

Please or to participate in this conversation.