I want to access a db field inside a relationship table. The (below) shown model has the field "type_id".
// The query (so far):
$page = Page::where('slug', $slug)
->with(['page_content' => function ($query) {
return $query->with('content')
->orderBy('order')
->get();
}])
->first();
// Model / Relationship
public function content()
{
if ($this->type_id == 1) {
return $this->hasMany(TypeOne::class, 'id', 'content_id');
}
if ($this->type_id == 2) {
return $this->hasMany(TypeTwo::class, 'id', 'content_id');
}
}
$this does provide the model structure, but there's no data in it. Is this even possible?