Call to undefined method MemberStatus :: all ()

0

After creating a model, one of them usually has 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 in the application a test: var_dump (MemberStatus :: all ());

Give this error:

  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 that.

Does anyone know what problem this is?

    
asked by anonymous 17.05.2015 / 17:43

1 answer

0

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

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

Make sure the two classes are in different namespace and if you are calling the correct method class.

I also see that you should be taking the first steps in Laravel. Some of the difficulties you encounter will disappear as you gain more experience and what seemed difficult will surely become quite easier over time.

    
05.07.2015 / 01:49