Vue Eloquent One to Many Foreign Data
This one has me stumped:
I have a Vue instance that is retrieving projects from a database all okay!
Each project is associated with a user and a team:
$projects = auth()->user()->currentTeam()->projects;
Works great - except it doesn't return the Team Name with the data, only the team ID.
How do I change
public function projects() {
return $this->hasMany(Project::class, 'team_id');
}
to make it return the team name as well as the ID with each project.
I have searched a lot but none of the examples I have found seem to relate to the auth() way of doing this retrieval.
Any help very much appreciated. Thank you!
Haha, classic - I just did it:
return $this->hasMany(Project::class, 'team_id')->with('team');
I am sure I tried this - I think I might have been missing the declaration in my project model
public function team()
{
return $this->belongsTo(Team::class);
}
Anyway - all good - thank you for reading my silly posts - hope it helps someone else :)
Please or to participate in this conversation.