Reputation: 11
i want the current user when add user in a team will save in database user id for this user not id for current user but when i use $user=User::all();
or $user=User::find($id);
don't work and have error:
Undefined property: Illuminate\Database\Eloquent\Collection::$id
and when use $user=Auth::user();
save the current user id
public function addUser($id)
{
$teams =TeamWork::find($id);
$user =User::all();
$teammember = new TeamMember;
$teammember->user()->associate($user->id);
$teammember->Teamwork()->associate($teams->id);
$teammember->save();
$users = User::pluck('username');
return View('teams.adduser' , compact('users'))->with('teams', $teams);
}
Upvotes: 0
Views: 1471
Reputation: 139
Salam Alikom,
You have two $id
here, $user->id
and $team->id
,
Firstly, you can't use $user->id
because all()
method returns array not object
. So you have to use $userId = Auth::user()->id
instead. andvar_dump($team)
to make assure that it has property id
.
Upvotes: 1