I'm going slightly mad.
I have an Event model and an Instance model. An Event hasMany Instances and each Instance belongsTo one Event.
In Eloquent I can therefore say:
Event::find(1)->instances
and list all the instances of an Event.
How can I do the reverse and get the Event information for a specific Instance? If I say:
Instance::find(1)->events
It just returns null
Models:
class Event extends Model {
public function instances()
{
return $this->hasMany('App\Instance');
}
public function categories()
{
return $this->belongsToMany('App\Category');
}
}
class Instance extends Model {
protected $fillable = [
'event_id',
'instance_date',
'venue',
];
protected $dates = [
'instance_date'
];
public function scopeMatchEventId($query,$id)
{
return $query->where('event_id', '=', $id);
}
public function events()
{
return $this->belongsTo('App\Event');
}
public function venues()
{
return $this->belongsToMany('App\Venue');
}
}