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?
– Caliel Sesan
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.
– Caliel Sesan
Isn’t it simpler to name your Migration better? Something like Creatememberstatustable
– gmsantos