Call to Undefined method Memberstatus::all()

Asked

Viewed 214 times

0

After creating a model, usually one of them has presented this problem:

Symfony Component Debug Exception Fatalerrorexception (E_UNKNOWN) Call to Undefined method Memberstatus::all()

The table in the database exists and was created by migrate:

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

class MemberStatus extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('member_status', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('id_member_status');
            $table->string('member_status',100);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('member_status');
    }

}

And the seeder:

class MaritalStatusSeeder extends Seeder{   
    public function run(){      
        DB::table('marital_status')->delete();      
        $marital = array(                               
            array(              
                    'id_marital_status'     =>  1,
                    'marital_status'        =>  'Solteiro',                 
                    'created_at'            =>  new DateTime,
                    'updated_at'            =>  '',
            ),
            array(              
                    'id_marital_status'     =>  2,
                    'marital_status'        =>  'Casado',                   
                    'created_at'            =>  new DateTime,
                    'updated_at'            =>  '',
            ),
            array(              
                    'id_marital_status'     =>  3,
                    'marital_status'        =>  'Separado',                 
                    'created_at'            =>  new DateTime,
                    'updated_at'            =>  '',
            ),
            array(              
                    'id_marital_status'     =>  4,
                    'marital_status'        =>  'Divorciado',                   
                    'created_at'            =>  new DateTime,
                    'updated_at'            =>  '',
            ),
            array(              
                    'id_marital_status'     =>  5,
                    'marital_status'        =>  'Viuvo(a)',                 
                    'created_at'            =>  new DateTime,
                    'updated_at'            =>  '',
            ),
        );
        DB::table('marital_status')->insert($marital);              
    }   
}

The model was then created:

class MemberStatus extends Eloquent{
    protected $table = 'member_status';
    public $timestamps = true;
    protected $fillable = array(    
        'id_member_status',
        'member_status',
    );
}

When calling a test in the application: var_dump(Memberstatus::all());

Makes this mistake:

Symfony Component Debug Exception Fatalerrorexception (E_UNKNOWN) Call to Undefined method Memberstatus::all()

It has happened in another model, what I did was create the table again. Dai worked, now not even with this.

Does anyone know what the problem is?

  • I just renamed the file and class to uMStatus. And it worked. But I really don’t know why. I want to keep the name of my class and my file as Memberstatus. What a problem this would be?

  • Honestly, the idea of Laravel like any other framework is to make life easier for the programmer. But if I have to study the causes of each paradigm of the tool, I end up more time 'searching' the possibilities of programming the task, if I go like this, soon I created my own framework. The company doesn’t stop, and it delays a lot. I believe that the error is internal, because I have other classes and I do the same thing, and they work perfectly, only in some cases that do not. This is the second I have to change the original name.

  • Isn’t it simpler to name your Migration better? Something like Creatememberstatustable

1 answer

0

It’s hard to be sure what the problem is, but I believe it might be to have two classes with the same name (MemberStatus).

You may be trying to call the method all() in class MemberStatus extends Migration instead of MemberStatus extends Eloquent?

Check that the two classes are in different namespace and that you are calling the correct method class.

I also see you must be taking your first steps on the Laravel. Some of the difficulties you encounter will disappear once you gain more experience and what seemed difficult will certainly become quite easy over time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.