父类中的laravel getTable

时间:2017-09-23 20:15:24

标签: php laravel oop laravel-5

我正在使用laravel 5,我有模型类

class Apartment extends Property
{
    protected $table = 'apartments';
}

和父类

abstract class Property extends Model
{

    protected $table = '';

    public function doSomthing ()
    {
        echo $table = $this->getTable(); //$this->table
    }
}

我如何阅读$ table(apartments)或在父类中获取表名

$这 - > getTable();和$ this-> table和self :: $ table not work

1 个答案:

答案 0 :(得分:-1)

class Apartment extends Property
{
    protected $table = 'apartments';

    public function __construct()
    {
        parent::__construct($this->table);
    }
}

abstract class Property extends Model
{

    protected $table = '';

    function __construct($var)
    {
        $this->table = $var; //$this->table should be 'apartments'

    }

}