I created an intermediate class between models and, actually, Model .

 class Transaction extends BaseModel abstract class BaseModel extends Model 

In the BaseModel class BaseModel I added the getClass() method

 protected function getClass($short = false) { $namespace = get_called_class(); if ($short) { $className = explode('\\', $namespace); $className = end($className); } else { $className = $namespace; } return $className; } 

Then I got an object of the Transaction model from the collection and try to call getClass()

As a result, the following error occurs:

ErrorException in Builder.php line 2345: Call to undefined method Illuminate \ Database \ Query \ Builder :: getClass ()

Question: Why do I get an error from the builder when I try to call the model method and how can I fix it?

  • You were told that you are trying to call the getClass method on another class. Illuminate\Database\Query\Builder - E_p
  • Thanks, Cap. I can't understand - why did it happen that instead of a model object, I have a builder? I already fulfilled the request and received a collection of models. - Oleg Shakhov
  • Calling to studio code - E_p

0