I'm trying to change a value in my DB for a single item, I use first() to get an item, but for some reason when I try this function, every entry with the same primary key has the authenticated user gets the attribute 'AreFriend' updated at 1, why?
public function acceptrequest($id)
{
$user = app('Dingo\Api\Auth\Auth')->user();
if (!$targetuser = User::find($id)) {
return response()->json(['status' => "The requested resource does not exists!"], 403);
}
if ($relation = $user->requestspending()->where('user_id', $targetuser->user_id)->first()) {
Friend::unguard();
$relation->AreFriend = 1;
$relation->save();
Friend::unguard();
Friend::reguard();
return response()->json(['status' => "Request accepted!"], 200);
} else {
return response()->json(['status' => "You do not have an invitation from this user!"], 403);
}
}
In my database, relations with the $user id are updated. The variable $relation is an item, not a collection.