Laravel model inheritance - how to call a function from parent model?
<p>In my Laravel 5.2 app, there is the following model hierarchy:</p>

<pre><code>//Model.php:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
abstract class MyModel extends Model {
    public function getAllColumnsNames() {
        ...
    }

//Article.php
namespace App\Models;
class Article extends MyModel {
    ...
}
</code></pre>

<p>Then in the controller, there is a function which gets $item as parameter and $item is of type App\Models\Article:</p>

<pre><code>//MyController.php
use App\Models\MyModel;
...
    public function japi ($item) {
        if (! $item instanceof MyModel) {
            return [];
        } else {
            $columns = $item-&gt;getAllColumnNames();
        }
    }
</code></pre>

<p>The last line throws an exception:</p>

<pre><code>Call to undefined method Illuminate\Database\Query\Builder::getAllColumnNames()
</code></pre>

<p>I expected that this function will be inherited from MyModel class but in fact it's called from Builder class.</p>

<p>How to call the function from MyModel in the controller?</p>

<p>[Edit]
Actually, even if I move the getAllColumnNames() function from MyModel directly to Articles class, the same exception is thrown. I'm stuck.</p>