I have a custom setter that I'm running in a __construct
method on my model.
This is the property I'm wanting to set.
protected $directory;
My Constructor
public function __construct()
{
$this->directory = $this->setDirectory();
}
The setter:
public function setDirectory()
{
if(!is_null($this->student_id)){
return $this->student_id;
}else{
return 'applicant_' . $this->applicant_id;
}
}
My problem is that inside my setter the, $this->student_id
(which is an attribute of the model being pulled from the database) is returning null
.
When I dd($this)
from inside my setter, I notice that my #attributes:[]
is an empty array.
So, a model's attributes aren't set until after __construct()
is fired. How can I set my $directory
attribute in my construct method?