-2

I am using Laravel 5 and I have model class

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

and parent class

abstract class Property extends Model
{
   
    protected $table = '';

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

how I can read $table (apartments) or get table name in parent class

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

OMR
  • 11,736
  • 5
  • 20
  • 35
Fathi
  • 138
  • 2
  • 2
  • 7

1 Answers1

-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'

    }

}
vnt
  • 611
  • 6
  • 13
  • Non-static method App\Property ::doSomthing () should not be called statically – Fathi Sep 23 '17 at 21:26
  • and after i add "static" to (public static function doSomething) i got <> – Fathi Sep 23 '17 at 21:27
  • 1. doSomthing can be called as usual like $this->doSomthing(); 2. if doSomthing has to be a static function, try to pass $this->table as an argument to doSomthing($table){...}, You can not use $this inside a static function – vnt Sep 23 '17 at 21:54
  • yes i already made this ( doSomthing($table) ) but i asked for a better solution and way big thanks to u – Fathi Sep 24 '17 at 10:34