You need to change your constructor to:
public function __construct(array $attributes = array()) { parent::__construct($attributes); $this->directory = $this->setDirectory(); }
The first line ( parent::__construct() ) will run the Eloquent Model own constructor method before running your code, which will configure all the attributes for you. Also, a change in the signature of the constructor method should continue to support the use that Laravel expects: $model = new Post(['id' => 5, 'title' => 'My Post']);
The thumb rule really should always be remembered when extending a class to make sure that you do not override the existing method so that it no longer runs (this is especially important with the magic of __construct , __get , etc.). You can check the source of the source file to see if it includes this method.
source share