working with Laravel 5.1 here. I have created two classes, one extending the other:
abstract class ActivityTimeline extends Model
Which has:
$this->fields = [
'owner_id',
'contact_name',
'mailing_label',
'source_id',
'source_raw',
'initial_referer_raw',
'primary_person',
'connections',
];
foreach ($this->fields as $field) {
if (method_exists($this, $field)) {
dd('the method exists', $this, $field);
$timelineActivity[$field] = $this->{$field}();
}
}
And
class ContactActivity extends ActivityTimeline {
Which has:
public function primary_person()
{
return $this->getPrimaryPerson($this->record);
}
The "dd('the method exists', $this, $field);" returns the following:
"the method exists"
ContactActivity {#963 ▶}
"primary_person"
However when this if statement passes, and I attempt to call the method that I just checked the existence of, I get:
BadMethodCallException in Builder.php line 2123: Call to undefined method Illuminate\Database\Query\Builder::primary_person()
So it seems that I'm not working with a ContactActivity object here, even though the dd shows that I am. Anyone know what I'm doing wrong here to get the wrong object?