I have User
and Project
models.
The relationship is mant to many.
public function projects()
{
return $this->belongsToMany('App\Project')->withPivot('id');;
}
And in Project
i have :
public function users()
{
return $this->belongsToMany('App\User')->withPivot('id');;
}
Now what i am doing :
$projectsAsFreelancer = App\Project::where('assignedTo',$id)->get();
What i want is to get the username
from the users
table of the user, Who have posted the project. The Project
means projects
table have the forign_key
->employeer_id
.
Currently $project->pivot->username
gives me error.
pivot
table name is project_user
.
What i am missing ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire