0
votes

I have a model extended from Model its name is IcerikRltCategory and i want to use getTable function with staticly. But __callStatic function does not fire anything. Because not entered this magic function scope.

Error message is:

1/1 ErrorException in ContentController.php line 51: Non-static method Illuminate\Database\Eloquent\Model::getTable() should not be called statically, assuming $this from incompatible context

1

1 Answers

0
votes

The getTable method requires an instance of the model object to work. The method itself look like this:

public function getTable()
{
    if (isset($this->table)) return $this->table;

    return str_replace('\\', '', snake_case(str_plural(class_basename($this))));
}

And as you can see it uses $this to access the property, which means in needs context given by an object instance. So calling the method statically won't work:

IcerikRltCategory::getTable(); // this won't work

However when you have an instance, it will:

$model = new IcerikRltCategory();
$model->getTable(); // this will work