I'm trying to add an attribute to my model so I can say something like: $model->path and then get back a url. So I've added the following to the model's constructor:
public function __construct($attributes = array()){
$this->path = url('img/' . $this->{'file-name'});
parent::__construct($attributes);
}
But if I run Model::first() then I get the following:
{
id: 25,
text: "A lovely file",
file-name: "file.jpg",
created_at: "2016-02-12 11:44:37",
updated_at: "2016-02-12 11:44:37"
},
You'll notice that there is no path attribute. Am I doing something very wrong?! I want to see:
{
id: 25,
text: "A lovely file",
file-name: "file.jpg",
path: "http://myapp.app:8000/img/file.jpg",
created_at: "2016-02-12 11:44:37",
updated_at: "2016-02-12 11:44:37"
},
For the record, I have also tried $this->field = 'value'; and that didn't create an attribute either.