How to return database table name in Laravel

There is a public getTable() method defined in Eloquent\Model so you should be able to use $model->getTable().


Taylor has an answer to your question:

Within the model class you can do something like this:

return with(new static)->getTable();

If you want all your models to have the ability to return table name statically, then so something like this:

class BaseModel extends Eloquent {

    public static function getTableName()
    {
        return with(new static)->getTable();
    }

}

class User extends BaseModel {

}


User::getTableName();